MADRID - Iker Castillas made a pair of diving saves in the final minutes, and Real Madrid advanced to the Champions League quarterfinals despite a wild 4-3 loss to Schalke on Tuesday night that left them with a 5-4 aggregate win in the home-and-home series.

Cristiano Ronaldo scored twice on headers, raising his Champions League goals total to 75, and the defending champions reached the quarterfinals for the fifth straight year.

"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."

Christian Fuchs put the visitors ahead in the 20th minute, and Ronaldo tied the score five minutes later.

Madrid made three defensive errors in a row that culminated with Klaas-Jan Huntelaar hitting a post in the 40th and scoring seconds later after connecting with Casillas' clearance of Max Meyer's shot.

Ronaldo scored his 75th career Champions League goal five minutes later, and Karim Benzema dribbled past two defenders for 3-2 lead in the 53rd.

Leroy Sane curled a shot over Casillas in the 57th, Huntelaar scored in the 84th and Casillas made a pair of diving saves in the closing minutes.

"We tried everything to stay in the competition, nevertheless, it was not enough," Schalke coach Roberto Di Matteo 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."

Hundreds of blue-clad Schalke fans were escorted to Estadio Santiago Bernabeu by riot police, who closedg off part of the city's main La Castellana boulevard, hampering rush-hour traffic. One bloodstained fan was arrested on Monday night in the downtown Puerta del Sol square after pouring beer over a police officer.

In the night's other game, Porto routed Basel 4-0 for a 5-1 aggregate win. Yacine Brahimi, Hector Herrera, Casemiro and Vincent Aboubakar scored for the hosts.