MONACO (AP) Rafael Nadal was prepared for pain. Roger Federer hoped to avoid pain.

They got what they wished for and reached the Monte Carlo Masters quarterfinals on Thursday.

Eight-time champion Nadal saved 15 of 17 break points, scampering all over the clay to retrieve big forehands from Dominic Thiem and beat the Austrian 7-5, 6-3.

Thiem beat Nadal in the semifinals in Buenos Aires en route to the title, the first of two on clay in February. Thiem has the second-most wins on the tour this year, after Novak Djokovic. He made Nadal run and run.

''I never gave up in all these tough moments,'' Nadal said. ''You need matches like this. You need to suffer on court.''

Federer was equally pleased to feel no pain in his left knee, two months after arthroscopic surgery for torn cartilage. In his second match since, Federer was unscathed in easing past Roberto Bautista Agut of Spain 6-2, 6-4 for a fifth straight time.

''I'm happy how the body is, that I was able to play two matches already here, and get a chance to play a third,'' Federer said. ''I'm getting closer to the peak in the sense of maximum movement.''

Federer next faces Jo Wilfried Tsonga in the last eight, leading the Frenchman 11-5 in head-to-heads.

''I like his game. I like his power, his capacity to move forward with his forehand,'' Federer said of Tsonga. ''I've seen wonderful matches of him against the best players, and also against me.''

Elsewhere, Andy Murray rallied from a set and 3-0 down to advance along with Stan Wawrinka, the only other former champion left in the field beside Nadal.

Nadal faced 16 of the 17 break points against Thiem in the first set.

At 4-4, and with each player having dropped serve once, Thiem missed six chances to break Nadal. On the last one, Thiem let a lob go thinking it was going out, and watched it land in.

The Spaniard clenched his fist after holding that tough game, and then broke Thiem when the Austrian double-faulted on set point.

''Some of the break points he played very well so I didn't have a chance, but there were also some where I really had some easy shots,'' said Thiem, who converted only one of 16 chances on Djokovic's serve in the third round of the Miami Masters two weeks ago. ''Of course, it's very frustrating.''

After Thiem broke Nadal to love in the third game of the second set for a 2-1 lead, Nadal quickly regained momentum and broke Thiem twice more to set up a quarterfinal against Wawrinka, the 2014 champion.

''If you look at the past year, we can see his level has slightly decreased,'' Wawrinka, the French Open champion, said of 14-time Grand Slam winner Nadal. ''But a champion like him is still able to win big titles.''

Murray was relieved to scrape past an erratic Benoit Paire of France 2-6, 7-5, 7-5.

''To win when you're not playing particularly well, it's a great effort,'' Murray said. ''It would have been easy to lose today and get down on myself. But I kept fighting.''

Paire had 47 winners among a number of eye-catching shots, but the Frenchman also made 52 unforced errors. He had eight aces and seven double-faults.

Paire also lost his composure at key moments, double-faulting when serving for the match and again on match point.

''He played a bad game at 3-0 in the second to give me one of the breaks back,'' Murray said. ''I felt like I was in with a chance then.''

Murray next plays Milos Raonic of Canada, who had 12 aces in beating 99th-ranked Damir Dzumhur of Bosnia and Herzegovina 6-3, 4-6, 7-6 (5).

Wawrinka advanced by routing Gilles Simon 6-1, 6-2, breaking the Frenchman's serve five times.

Since losing his first 12 matches against Nadal, Wawrinka has won three of their past five encounters, including the final of the 2014 Australian Open, his first major.

The day after stunning Djokovic in the second round, 55th-ranked Jiri Vesely of the Czech Republic lost to Gael Monfils 6-1, 6-2.

Monfils next plays Spaniard Marcel Granollers, who upset David Goffin of Belgium 7-6 (1), 6-4, while Tsonga downed countryman Lucas Pouille 6-4, 6-4.