Cristiano Ronaldo has rescued Real Madrid in the Champions League with two goals in a 4-3 defeat to Schalke that saw the holders squeeze through to the quarterfinals with a 5-4 victory on aggregate.
Madrid's first scare of the Tuesday night came when Schalke's Christian Fuchs opened the scoring in the 20th minute, only for Ronaldo to head an equalizer for the hosts five minutes later from Toni Kroos' corner.
Madrid then made three defensive errors in a row that culminated in Klaas-Jan Huntelaar hitting the post in the 40th and scoring seconds later after connecting with Madrid 'keeper Iker Casillas' clearance of a Max Meyer shot.
Ronaldo headed home again five minutes later to set an all-time record of 78 goals in UEFA club competitions, one more than former Real Madrid forward Raul Gonzalez, and settle nerves at the Santiago Bernabeu Stadium.
France striker Karim Benzema then dribbled past two defenders before calmly steering home Madrid's third goal in the 53rd minute.
However, Schalke's Leroy Sane curled a superb shot over Casillas in the 57th to level on the night before former Madrid player Huntelaar made it four for Schalke in the 84th. One more goal for the German side in the final minutes would have sent it through on the away goals rule with a sensational result.
"We had problems in all aspects of our game," Madrid coach Carlo Ancelotti said. "We have to say it clearly, we are playing very badly. It's almost incomprehensible considering how we were playing before Christmas."
Ancelotti said the return from injury of Sergio Ramos will help the team because the defender provides a "sense of responsibility and character."
Schalke coach Roberto Di Matteo was meanwhile stoical in defeat.
"We tried everything to stay in the competition, nevertheless, it was not enough," he said. "We are happy we won, but we scored four goals and were eliminated.
"Madrid didn't get their pace because we didn't let them, but in the end they proved their quality, with very few chances they scored three goals."