A thrilling LaLiga title race looked to be turning in Atleti's favor after a spirited Osasuna display held Madrid at bay for much of Saturday's late game, but Zinedine Zidane's team struck in the 76th minute.
Militao, who had previously been denied by Sergio Herrera, headed home from Isco's delivery to snatch a vital win and pull Los Blancos within two points of leaders Atleti, keeping up the pressure on Barcelona and Sevilla in the meantime.
It was a cruel blow for Osasuna, who had looked in good position to end a 16-year losing streak at Madrid, and Casemiro's fortuitous finish sealed the result.
Making his first start since January, Eden Hazard had an early sighter, curling over the corner of the goal after a driving run from the left.
Hazard went closer still in the 26th minute, drawing a brilliant save from Herrera with a close-range volley.
Herrera pulled off another superb stop from the resulting corner, flicking Militao's goal-bound header over, with Vinicius Junior slamming into the side netting soon after.
Osasuna thought they had pinched the lead on the stroke of half-time, only for Chimy Avila's fine header to be disallowed for offside.
Militao flashed an acrobatic attempt over the bar after the restart, with substitute Rodrygo Goes arrowing a crisp effort just wide in the 67th minute.
Coach Zidane soon turned to Isco, and the playmaker immediately repaid the faith, clipping in a corner from which Militao sent a towering header into the right corner.
The points were sealed four minutes later – Benzema slipping a neat pass through for Casemiro, whose heavy first touch wrong-footed Herrera and rounded off a hard-earned win.