Ronaldo headed home his second goal of the game in the 89th minute as Madrid, who twice trailed, moved back to within a point of leaders Barcelona with three games remaining.
This was Madrid's 17th win in 18 league encounters at the Bernabeu this season, but they had to do it the hard way after Osasuna went ahead through first-half goals from Carlos Aranda and Krisztian Vadocz.
However, Pellegrini's men hit back both times through Ronaldo and Marcelo to go into half-time at 2-2 and then, having rode their luck on occasion after the break, claimed the points when Ronaldo netted his 22nd league goal of the season.
Pellegrini said of Ronaldo: "He's a player who makes the difference and we are fortunate he's with us."
Pellegrini also praised his side's fighting spirit, adding: "I think the team is very strong, especially on a psychological level. This is vital in the final stage of the season."