WIMBLEDON, England — Perhaps the surface and the setting matter in men’s tennis, after all.


Roger Federer had lost six of seven matches to Novak Djokovic, most recently last month in a dispiriting, straight-set affair in the French Open semifinals.


But that was on red clay during a soggy second week in Paris when it was even tougher than usual to breach Djokovic’s formidable defenses.


Wimbledon was rainy, too, on Friday. But Centre Court now has a retractable roof and so Federer, with his suspect back and grand plans, was able to stay safe and dry on his favorite tennis court; able to shift the momentum of a great rivalry back his own way with a stirring and surprising 6-3, 3-6, 6-4, 6-3 victory in the semifinals.


“Obviously I’m ecstatic; I’m so happy,” Federer said. “I played a great match today.”


It was the 27th match between Federer and Djokovic, but their first on grass.


“I think over all the surface made the match play differently and potentially in my favor,” said Federer, who holds a 15-12 edge over all.


At age 30, Federer, the smooth-moving and enduring Swiss champion, is now just one victory away from tying William Renshaw and Pete Sampras with a seventh Wimbledon singles title. He is also only one victory away from reclaiming the No. 1 ranking.


To cross those thresholds, he will have to defeat Andy Murray, who defeated Jo-Wilfried Tsonga of France, 6-3, 6-4, 3-6, 7-5, in the other semifinal Friday. The last British man to reach the final was Bunny Austin in 1938, and the last British man to win it all was Fred Perry in 1936. While Federer and Djokovic, the defending champion, played indoors Friday, Murray and Tsonga were set to begin their match outdoors after a break in the foul weather at Wimbledon.


Djokovic said he did not believe that playing indoors had given either player an advantage.


“We both know what it’s like to play under the roof under these conditions,” he said. “And I thought the beginning of the match, it was a little bit slippery in the back of the court. After that it was good conditions to play on, and we both got used to it.”


But playing indoors certainly seemed to help Federer on his serve. Djokovic, arguably the world’s best returner, was able to break him just once. That came in the second set when Djokovic appeared to have taken control of the match after a quick start from Federer.


At that stage, Djokovic was winning a clear majority of the baseline rallies, holding serve effectively and making Federer lunge and scrape for volleys when he did manage to get to net.


But Federer was able turn the match in the third set despite failing to capitalize on opportunities on Djokovic’s serve in the sixth game. But with Djokovic serving at 4-5, the Serb retreated to hit an overhead and missed it long to give Federer two set points at 15-40. Djokovic saved the first but could not save the second as Federer attacked and hit a lunging overhead of his own for a winner.


Sitting in his chair, Djokovic appeared drawn and weary, breathing hard, his lips parted.


“Last five or six days I haven’t been feeling that great, but I don’t want to talk about it right now,” Djokovic said later.


Djokovic declined to elaborate, but he did seem low on energy, even inspiration, as the match progressed. Federer broke him with relative ease in the second game of the fourth set and was quickly up 3-0. Djokovic kept himself in touch by rallying to hold serve in the sixth game from 0-40 down, but he could never get a break point on Federer’s serve down the stretch.


Federer held to 5-2 and then held for the victory when Djokovic knocked his final return of the afternoon into the net. It has been more than two years since Federer won a Grand Slam title, but he is now in position to extend his career record by winning a 17th.


“Of course I do have a respect for Roger and everything he has done,” Djokovic said. “Of course it goes to his credit, the history that he has. But when you’re on the court, you don’t think about it.”