Ronaldo brought Real level with a strike from the edge of the area but as Real continued to press Krisztian Vadocz smashed in Osasuna's second.
In a breathless conclusion to the first half, Marcelo scored a rare header to equalise to Real again.
Substitute Masoud Soleimani missed an open goal for Osasuna as the visitors missed several excellent chances and the game appeared to be heading for a draw until Ronaldo headed home a Gonzalo Higuain cross from close range.
"Osasuna made us suffer a lot. It was the worst performance defensively this year although we did deserve to score three goals," said Real coach Manuel Pellegrini.
"The calendar is equally bad for both teams now (Real and Barcelona) and I think everything will be decided in the final week. My players are in good spirits, that is important for our last three games and so all we can do is push Barcelona to the end."
Mallorca, the surprise package this season, had dropped down to fifth with Sevilla's 3-1 victory over Atletico Madrid earlier in the day but scoring against the run of play they came away winners from Bilbao to regain fourth behind Valencia.
Fernando Llorente in turn headed Athletic back on level terms two minutes later but it all fell apart for the home side at the start of the second half with Jose Nunes flicking a ball home from a corner and then Aritz Aduriz slotting in the third.
An Alvaro Negredo penalty double helped Sevilla beat Atletico Madrid.
In a forerunner of the Copa del Rey final later this month, there was a flurry of early goals with an unmarked Luis Fabiano putting the home side ahead after five minutes.
Tiago Cardoso then levelled after latching onto a loose ball in the box.
Negredo restored Sevilla's advantage with a penalty after Juan Valera upended Adriano Correia and then, six minutes before half-time, scored his second spot kick following a foul by Luis Perea on Fabiano.
It was a crude challenge by the Colombian which forced Fabiano off the pitch with an ankle injury which is expected to keep him out for up to ten days and puts him in danger of missing the cup final.
"It was not an easy game as the Atletico players are professionals and did not make it easy for us," said Sevilla coach Antonio Alvarez.
"Fabiano's ankle is swollen but it is not as bad as we thought at first and he should be okay for the cup final (May 19)."
Source: AFP Global Edition