We present a calculation of the hadronic vacuum polarization contribution to the muon anomalous magnetic moment, a μ hvp, in lattice QCD employing dynamical up and down quarks. We focus on controlling the infrared regime of the vacuum polarization function. To this end we employ several complementary approaches, including Padé fits, time moments and the time-momentum representation. We correct our results for finite-volume effects by combining the Gounaris-Sakurai parameterization of the timelike pion form factor with the Lüscher formalism. On a subset of our ensembles we have derived an upper bound on the magnitude of quark-disconnected diagrams and found that they decrease the estimate for a μ hvp by at most 2%. Our final result is aμhvp=(654±32−23+21)·10 −10, where the first error is statistical, and the second denotes the combined systematic uncertainty. Based on our findings we discuss the prospects for determining a μ hvp with sub-percent precision.