Real are flying in Europe after resounding Champions League victories over Galatasaray and FC Copenhagen but turned in another disappointing domestic performance following last weekend's 1-0 defeat at home to Atletico Madrid.
They twice had to come from behind at Levante's Ciutat de Valencia stadium before Ronaldo rifled a shot from the corner of the area and it glanced off a defender before ricocheting into the net off a post.
It was desperately hard on a plucky Levante side and their fans but moved Real back above Villarreal into third place, within two points of champions Barcelona and Atletico.
"The first half was not good but the second turned out differently," Real coach Carlo Ancelotti told a news conference.
"We need more concentration because we gifted two goals," added the Italian. "The team dug deep at the end and never gave up. When our team plays, five minutes is all it takes to win a game."
Barca and Atletico have both won all seven matches and can restore their five-point advantage over Real with respective victories against Real Valladolid later on Saturday and against Celta Vigo on Sunday.
Levante, whose entire squad is worth just over a third of the record 100 million euros Real paid for Wales winger Gareth Bale in the close season, took the lead in the 57th minute when Papa Babacar Diawara finished off a superb counter attack.
The goal appeared to wake the Real players from their lethargy and Sergio Ramos levelled four minutes later when he volleyed home an Angel Di Maria corner.
Levante rallied and substitute Nabil El Zhar fired through a crowd of defenders into the net in the 86th minute to put the home side within touching distance of an unlikely victory.
There was still time for plenty more drama and Real substitute Alvaro Morata levelled when he blasted the ball in from close range in the 90th minute.
Ronaldo, who ripped off his shirt after scoring the winner, now has seven goals in the league this season, one behind Barca's World Player of the Year Lionel Messi and Atletico forward Diego Costa.