SHANGHAI (AP)—Defending champion Andy Murray held off a late rally by Switzerland’s Stanislas Wawrinka to advance to the quarterfinals of the Shanghai Masters with a 6-4, 3-6, 6-3 victory on Thursday.

After dropping the second set, the second-seeded Scot broke Wawrinka twice to race out to a 5-0 lead in the third. But Wawrinka battled back to take the next three games before Murray finally closed it out.

It was Murray’s first match in Shanghai after receiving a first-round bye and a walkover in the second round when Russian Dmitry Tursunov pulled out with an injury.

Third-seeded David Ferrer also advanced after saving three match points against countryman Juan Carlos Ferrero in a 1-6, 7-5, 6-2 win, and Andy Roddick also moved on with a 6-3, 6-4 win over Spain’s Nicolas Almagro.

Ferrer was outplayed by his veteran opponent from the start, dropping his serve three times in the opening set and then facing three match points while serving at 4-5 in the second.

The third-seeded Spaniard hit two booming serves and a forehand winner to stay in the match, then broke a deflated Ferrero in the next game on his way to taking the set and the match.

“It was amazing, no?” said Ferrer, who secured his place in the ATP Tour World Finals with the victory. “I had three match balls down. I (served) very good in important moments. After this game I make the break up very fast.”

Roddick had a far easier time, hitting 11 aces and 23 winners to beat the seventh-seeded Almagro.

“I feel like today was significantly better than the first two rounds as far as putting it all together,” said the 10th-seeded Roddick, who faces Ferrer in the next round.

Roddick is trying to finish his season on a positive note after struggling with injuries, crashing out in the third round of Wimbledon and losing the No. 1 American ranking to Mardy Fish.

After reaching the quarterfinals of the U.S. Open last month, he fell in the first round of the China Open in Beijing and bristled at a question from a reporter about whether he was contemplating retirement.

His play against Almagro, ranked 11th in the world, suggested retirement may be some way off. He won 91 percent of points on his first serve—32 of 35 points—and captured 10 of 12 points at net. He never faced a break point.

“As far as the way I’ve been hitting the ball and playing, it’s been OK. But the serve’s been up and down,” Roddick said. “I was going like in spots where I’d make three serves in a row, but then miss four or five. It’s those gaps where you’re hitting second serves where guys get a look. I cleaned that up a little bit today.”

Alexandr Dolgopolov, the 12th seed from Ukraine, dropped the first set against Australian teenager Bernard Tomic, then reeled off 12 of the last 13 games to win, 5-7, 6-1, 6-0. And Kei Nishikori continued his good run—he beat Jo-Wilfried Tsonga in the second round—by beating Colombia’s Santiago Giraldo 7-6 (6), 4-6, 6-3.