We present theoretical results for the equilibrium Josephson current through an Anderson dot tuned into the magnetic regime, using Hirsch-Fye Monte Carlo simulations covering the complete crossover from Kondo-dominated physics to π junction behavior in a numerically exact way. Within the 'magnetic' regime, U/Γ ≫ 1 and ǫ0/Γ ≤ 1, the Josephson current is found to depend only on ∆/TK , where ∆ is the BCS gap and TK the Kondo temperature. The junction behavior can be classified into four different quantum phases. We describe these behaviors, specify the associated three transition points, and identify a local minimum in the critical current of the junction as a function of ∆/TK . PACS numbers: 74.50.+r, 72.15.Qm, 75.20.Hr Recent advances in nanoscale manipulation and fabrication call for a deeper understanding of the effect of electronic correlations. Due to the complexity of its theoretical treatment, the interplay between superconductivity and magnetism belongs to the least understood phenomena in that respect. Here we study the Josephson current I(φ) through a correlated nanoscale quantum dot contacted by s-wave BCS superconductors. At low enough temperatures, such a dot is generally described by the Anderson impurity model indicated in Fig. 1. We consider the regime U/Γ ≫ 1 and ǫ 0 /Γ ≪ −1, where the dot effectively has single occupancy and thus represents a spin-1/2 degree of freedom. Then a complicated interplay between this magnetic impurity and the superconductivity in the leads sets in. Some aspects of this physics were recently observed in Andreev conductance measurements for a short multi-wall nanotube [1,2]. A similar setup should also allow to probe the Josephson current in the near future, where the ratio ∆/T K is widely tunable via a backgate voltage.In this paper, we provide a detailed analysis and classification of all possible phases expected in such an experiment. We find that only one 'master' parameter ∆/T K governs this problem, whereis the Kondo temperature for normal leads [3]. For ∆/T K ≪ 1, the Kondo effect survives and is only weakly affected by superconductivity, while for ∆/T K ≫ 1, perturbation theory in Γ yields an inverted Josephson relation I(φ) = −I c sin φ [4,5,6,7], where φ = π represents a minimum of the junction free energy F (φ). Such a π junction behavior was recently reported in Nb-Cu x Ni 1−x -Nb systems [8], is related to subgap (Andreev) bound states [9,10], and implies broken time-reversal symmetry. In both limits, analytical expressions [6] are reproduced by our method below. For a magnetic impurity, the Josephson relation is generally replaced by a more complicated dependence on φ. A classification into four types of junctions, labeled as 0, 0 ′ , π ′ and π, follows from the respective stability of the φ = 0 and φ = π configurations [9].For a 0 (π) junction, only φ = 0 (φ = π) is a minimum of F (φ). For the two other cases, both φ = 0, π are local minima, and depending on whether φ = 0 (φ = π) is the global minimum, one has a 0 ′ (π ′ ) junction. Using I(φ) = (2e/ )d...