Roger Federer will be the world number one for a remarkable 300th week, after a hard-fought win over good friend Stanislas Wawrinka.

The 17-time Grand Slam champion needed to make at least the quarterfinals of the Shanghai Masters to keep his hold of the number one ranking, and despite a few hiccups, he did just that with a 4-6, 7-6, 6-0 victory over his Swiss compatriot.

"I had my chances in the second set," Federer told reporters. "I was up a break. Then I think I was down breakpoint at one point at the end of the second set.

"Obviously that was like a match point. So I knew I had a chance going into the breaker.

"I thought we both played a pretty good breaker. Could have gone either way. Consider myself a little lucky. I never stopped believing, pushed till the end, then got off to a good start in the third set. Basically that was it.

"It was a tough match. He was the better player for basically two sets. It's great finding a way out that way, that's for sure."

Federer said completing 300 weeks at the top was "one of his biggest accomplishments."

"It's obviously an amazing number," he said. "I never thought of something like this when I was a little kid, that's for sure.

"I was just hoping one day my dream was going to come true to play on the regular tour, play Wimbledon, maybe become world No. 1 at some stage.

"So here I am at 300 weeks. It's pretty incredible. Probably one of my biggest accomplishments. I'm very proud of that record, no doubt about it."

Federer still considers his first week as world number one, way back in 2004, as one of his biggest achievements. "I remember it very vividly," he added. "It's not one of those moments that happens and then you forget. It took me a lot of great performances to get there.

"I had an opportunity I think in the match against (Andy) Roddick in Montreal. Lost 7-6 in the semis there against him. It took me to win Wimbledon, the World Tour Finals, then basically get to the finals of the Australian Open. After beating (Juan Carlos) Ferrero in the semis, I knew I clinched it, but obviously I wanted to finish the tournament on a high note winning the Australian Open as well.

"That's what I was able to do then. But I remember after the semis how happy I was becoming world No. 1. It was for me back then sort of the ultimate accomplishment next to winning Wimbledon.

"That all happened in a span of nine months, which was so intense, huge relief in some ways, but big satisfaction.

"Here I am eight years later, even more. It's pretty special. Obviously I lost the world No. 1 ranking a few times, but I also stayed a long time once I got there. I always felt tennis was easier for me playing as world No. 1 than actually getting there."