WIMBLEDON, England (AP)—Roger Federer leaned on the net, exhausted but exhilarated after winning the final set 19-17 to earn his first Olympic singles medal.

"It has been a long time coming," he said.

The wait included an Olympic marathon Friday, when Federer played for 4 hours, 26 minutes to beat Juan Martin del Potro of Argentina 3-6, 7-6 (5), 19-17. It was the longest three-set men's match of the Open era.

"I definitely got a sense that it was something special," the top-seeded Federer said. "The deeper we went into the match, the more I thought, 'Wow, this is so cool to be part of a match like this.'"

Federer converted only two of 13 break-point chances, the second coming in the next-to-last game, and had several nervous moments. But he held serve 12 times in the final set to stay in the match.

With the comeback victory, the four-time Olympian is assured of at least a silver. On Sunday he'll play in the final against Great Britain's Andy Murray in a rematch of the Wimbledon final. No. 3 seed Murray defeated second-seeded Novak Djokovic of Serbia, 7-5, 7-5, in the second semifinal.

Federer rallied past Murray in last month's Wimbledon final that dropped Murray's record in Grand Slam finals to 0-4.

"I'll be desperate to win on Sunday," he said.

Murray held all 12 of his service games and broke once in each set. When he ripped his final shot at Djokovic's feet for a winner, the partisan Centre Court crowd responded with a roar.

"It was one of the biggest wins of my career, and one of the most emotional - so, so happy to win," the usually dour Murray said. "You don't see me smiling that much normally, and I haven't stopped smiling since I came off the court."

Del Potro will play Djokovic for the bronze. Djokovic won the bronze in 2008.

In 2008, Federer and Swiss teammate Stanislas Wawrinka won the gold in doubles. But Federer had been 0 for 3 in Olympic singles, the biggest blemish on a resume that includes a record 17 Grand Slam titles.

Serena Williams also clinched her first Olympic singles medal, beating No. 1-seeded Victoria Azarenka 6-1, 6-2. On Saturday, the No. 4-seeded Williams will face first-time Olympian Maria Sharapova, who beat Russian teammate Maria Kirilenko 6-2, 6-3.

Williams teamed with sister Venus to win the gold in doubles in 2000 and 2008. They have a chance to clinch at least a silver in the semifinals Saturday.

Americans Bob and Mike Bryan are assured of at least a silver after beating Julien Benneteau and Richard Gasquet of France 6-4, 6-4 in the semifinals of men's doubles. Mike Bryan and Lisa Raymond advanced to the first Olympics mixed doubles final since 1924 by beating Del Potro and Gisela Dulko 6-2, 7-5.

For duration, Federer's latest victory didn't rival John Isner's 70-68 final-set win at Wimbledon in 2010, or even Jo-Wilfried Tsonga's 25-23 win in the third set at the Olympics this week. But the match offered epic drama magnified by the setting and the stakes for Federer.

He improved to 12-0 this summer at the All England Club, including a record-tying seventh Wimbledon title a month ago.

There were no match points until the final game. After a couple of wobbly moments by Federer, including a double-fault, he sealed the victory when Del Potro dumped a backhand in the net.

Federer lifted his arms in jubilation, then leaned wearily on the net while awaiting congratulations from the big Argentine. They shared a warm embrace.

"I felt for him in a big way," Federer said, "because I've been there as well."

Said Del Potro: "It's not an easy situation. Someone always has to win these matches, and today it was his turn."

The 6-foot-6 Del Potro had the edge for most of the first two sets, reaching the net more often and winning the majority of the baseline rallies, starting with a 23-shot exchange in the opening game. He showed little apparent effort as he snapped explosive forehands that had Federer scrambling and lunging.

"Not enough, Roger!" a British spectator shouted when Federer fell behind.

The near-capacity crowd on sunny Centre Court was clearly in Federer's corner. Fans clapped and chanted "Ro-ger!" during a changeover, and later "Let's go, Roger!" More than once a Swiss cowbell clanged.

Small clusters of Argentine fans broke into song, and the match - like the entire tournament - took on an atmosphere more festive than during Wimbledon.

Federer's comeback came slowly. He was on the verge of digging a deeper hole midway through the second set, when he faced a break point and needed 16 points to hold for a 3-2 lead. He played another patchy game at 4-all, when he misplayed an overhead, blew an easy volley, squandered a 40-love lead and faced another break point.

He managed to hold again, and never trailed in the tiebreaker. Then the match proceeded on even terms for the next couple of hours.

In the 15th game of the final set, Del Potro twice won rallies after clipping the net cord with shots, the second time to erase a break point. Federer's bad luck had him screaming in frustration.

But for the most part, he managed to keep any annoyance in check. In the 31st game of the final set, when he mishit back-to-back forehands - the second sailed long - he gave his wife a wry grin.

"I was very tense at certain times," Federer said. "I was seeing myself as a loser many times during the match. But at the same time also I did see myself with medals. So you go through many emotions."

Federer broke for the first time in the 19th game of the final set when Del Potro double-faulted twice. That gave Federer a chance to serve for the victory at 10-9, but he was broken at love.

He waited 16 games for another chance, while repeatedly holding easily. Del Potro made three unforced errors in the 35th game to lose serve for only the second time, and eight points later the marathon reached the finish line.