We compute all K3 surfaces with Picard rank 20 over Q. Our proof uses modularity, the Artin-Tate conjecture and class group theory. With different techniques, the result has been established by Elkies to show that Mordell-Weil rank 18 over Q is impossible for an elliptic K3 surface. We also apply our methods to general singular K3 surfaces, i.e. with geometric Picard rank 20, but not necessaril...