PARIS -- Stanislas Wawrinka seemed on his way out of the French Open, down two sets and playing Frenchman Richard Gasquet.

Then, in the next set, it seemed to get even worse. Wawrinka was fuming. He ranted at the umpire several times, demanding that the line judge be changed.

Somehow, Wawrinka managed to put the anger aside Monday and won 6-7 (5), 4-6, 6-4, 7-5, 8-6 to reach the quarterfinals at Roland Garros for the first time.

"I think we had quite a few mistakes during the match with the umpire and with the judge line," Wawrinka said. "I'm really, really happy to win that match."

With Gasquet under pressure on his second serve in the last set, Wawrinka unleashed a powerful forehand down the line to end it.

"It was a crazy match. Richard forced me to play my best tennis and I played at my best level," Wawrinka said. "There was such an atmosphere that it felt like a Davis Cup tie. I don't know how I got away at the end."

Wawrinka, seeded ninth, will play seven-time champion Rafael Nadal of Spain, who earlier celebrated his 27th birthday with 6-4, 6-1, 6-3 win against Kei Nishikori of Japan.

"I don't want to think about my next (match)," Wawrinka said. "Even if I know it's Rafa."

Gasquet, seeded seventh, saved seven break points in his first two service games and fought back from 3-1 down in the tiebreaker. Ordinarily restrained, Gasquet punched the air after clinching the first set when Wawrinka hit a backhand into the net.

Down 3-0 in the second set, Wawrinka had his right thigh massaged. Gasquet pulled away at 5-1 before Wawrinka won three straight games. Gasquet won the second set with an ace, making windmill motions with his arms to get the crowd going on court Suzanne Lenglen.

"I had so many chances. He played incredibly well," Gasquet said. "It's incredibly sad but that's tennis. You have to bounce back."

It looked as if the match was slipping away from Wawrinka in the third set when his frustration got the better of him. He was unhappy at some calls from the line judge -- and let the umpire know it.

"The ball's there and he says nothing. He says nothing," Wawrinka shouted. "Yes, yes ... replace him at the next changeover."

After the fifth game, a tournament official came onto the court to speak to Wawrinka and the umpire.

"I want to change the guy," Wawrinka said. "How can he say fault?"

His request to change the line judge was refused, making him even more irate.

"Come on, there is 20 people," Wawrinka said. "That's not a small mistake, that's a big, big (mistake)."

Gasquet, who was sitting on his chair, intervened to tell Wawrinka to leave the matter alone.

"Take it easy, take it easy," Gasquet said in French.

But Wawrinka was angry. After the seventh game, while getting his right thigh wrapped, he claimed the official had gone back on his pledge to change the line judge.

"Don't take me for stupid. He told me, `Yes I will do next changeover.' So why he told me that?" Wawrinka asked.

Wawrinka saved a break point in the 11th game and evened the match in the next with a forehand winner. As for Gasquet, fatigue seemed to be a factor. He took a medical timeout at the start of the fifth set.

"Of course, it's disappointing," he said. "But I couldn't give any more than what I gave today."

Gasquet has been in this spot before -- losing Grand Slam matches after being up two sets: against Andy Murray in the first round at the 2010 French Open and the fourth round at 2008 Wimbledon, and Fernando Gonzalez in the third round of the 2009 Australian Open.

"I know that after three and a half hours of play, I start to get tired," Gasquet said.

And Wawrinka targeted that weakness.

"I was thinking to make him work, to make him work hard," Wawrinka said. "I can keep my level doing five hours, that's not the problem. But for him, I don't think it's the same."

Gasquet's concentration had wavered by the 14th game. At 15-30, he hit a backhand -- his best weapon -- that flew way out, giving Wawrinka two match points.

He needed only one.