After both sides struggled to create clear-cut chances in a nervy first-half, Leao broke clear to open the scoring, and Hernandez capped an incredible run with a fine left-footed finish to provoke jubilant scenes at San Siro.
Milan will only need to avoid defeat at Sassuolo on the final day of the season to clinch its 19th Scudetto after winning their fifth consecutive Serie A contest.
Sandro Tonali dragged a long-range effort wide as both sides made a tentative start to the game, before in-form forward Leao clipped a tame effort into Juan Musso's arms.
Luis Muriel drew a smart save from Mike Maignan from distance after half an hour, before Leao sent a wild effort high and wide as Milan struggled to create first-half opportunities.
Atalanta went close when Davide Zappacosta's effort deflected over within three minutes of the restart, before Hernandez came within inches of breaking the deadlock when he hit a 30-yard free-kick into the side-netting.
But Milan made the all-important breakthrough after 56 minutes, Leao racing onto Junior Messias' pass to finish neatly through the legs of Musso, with the furious visitors believing Matteo Pessina was fouled in the build-up.
Hernandez then sealed the victory with a goal worthy of deciding any title race, picking the ball up near his own box and driving towards the Atalanta area before finishing into the bottom-right corner, leaving Milan within touching distance of glory.