Rafael Nadal ended the run of Latvian qualifier Ernests Gulbis at the BNP Paribas Open with a 4-6, 6-4, 7-5 victory that set up a quarterfinal against defending champion Roger Federer, who survived a three-set marathon of his own, beating 18th-seeded Stanislas Wawrinka 6-3, 6-7 (4), 7-5.

Gulbis was on a 13-match winning streak, having made his way through the qualifying rounds at Delray Beach, Fla., where he won the title, and at Indian Wells, where he won three main-draw matches, including two over seeded players.

He was playing his 14th match in 19 days, and has yet to beat Nadal in five tries.

"I think that I played better tennis. I was more aggressive," Gulbis said. "I went for my shots much more than he. But he did really incredibly well, as he always does, on important points."

Gulbis held serve to lead 5-4 in the third. He led 30-15 on Nadal's serve, but lost the next five points to let Nadal tie the set.

Nadal earned the only break of the third to go up 6-5, then closed out the win on his third match point. He leaped, tore off his headband and pumped his left arm, yelling, "Yeah!"

"With all the problems, I was able to keep being focused and keep winning," he said. "I really appreciate every moment and every victory."

The fifth-seeded Spaniard opened his bid for a third Indian Wells title with a two-set victory over American Ryan Harrison, Nadal's first hard-court match in nearly a year.

He returned to the ATP Tour a month ago, winning two of three tournaments on clay after missing seven months because of a left knee injury. Nadal, shaken by an earthquake that rattled Indian Wells on Monday, had a walkover in his third-round match when Leonardo Mayer withdrew with a bad back.

"I said before the tournament my knee, some days good, some days not that good. Today so-so," he said. "But I fought. I fought every ball."

Nadal will go on to face Federer as top-ranked Novak Djokovic defeated Sam Querrey 6-0, 7-6 (6) to reach the quarterfinals.

Based on reporting by the Associated Press.

Follow us on twitter.com/foxnewslatino
Like us at facebook.com/foxnewslatino