In a previous Letter [Borsanyi et al., Phys. Rev. Lett. 111, 252001 (2013)] we determined the isospin mass splittings of the baryon octet from a lattice calculation based on Nf=2 +1 QCD simulations to which QED effects have been added in a partially quenched setup. Using the same data we determine here the corrections to Dashen's theorem and the individual up and down quark masses. Our ensembles include 5 lattice spacings down to 0.054 fm, lattice sizes up to 6 fm, and average up-down quark masses all the way down to their physical value. For the parameter which quantifies violations to Dashen's theorem, we obtain ɛ =0.73 (2 )(5 )(17 ), where the first error is statistical, the second is systematic, and the third is an estimate of the QED quenching error. For the light quark masses we obtain, mu=2.27 (6 )(5 )(4 ) and md=4.67 (6 )(5 )(4 ) MeV in the modified minimal subtraction scheme at 2 G e V and the isospin breaking ratios mu/md=0.485 (11 )(8 )(14 ), R =38.2 (1.1 )(0.8 )(1.4 ), and Q =23.4 (0.4 )(0.3 )(0.4 ). Our results exclude the mu=0 solution to the strong C P problem by more than 24 standard deviations.