Federer's forehand caused Ferrer problems throughout the match
Top seed Roger Federer will meet second seed Rafael Nadal in Sunday's Madrid Open final after both players secured three-set wins in the semi-finals.
Federer got the better of Spain's David Ferrer 7-5 3-6 6-3 to reach his first decider since the Australian Open.
Ferrer battled well, especially in the second set, but Federer upped his game in the third set to seal the win.
Earlier, Nadal battled back from a set down to beat fellow Spaniard Nicolas Almagro 4-6 6-2 6-2.
Sunday's final will be the first meeting between the players since last year's decider in Madrid which Federer won.
Federer, who had beaten Ferrer in all nine of their previous meetings, served superbly in the first set, losing only two service points while Ferrer had to save two break points on his second service game.
Although Federer was in control, the Spaniard stayed level, saving a further three break points at 4-4.
However, a forehand winner down the line gave Federer another break point at 5-5 and this time he converted it when Ferrer hit the net before serving for the set.
In the second set the top seed's serve faltered and Ferrer took the third of three break points to go 3-1 up before holding serve to take the second set.
Both players racked up unforced errors in the third set before Federer earned a break point with a crosscourt winner followed by a long forehand from Ferrer and the defending champion took the chance before serving for the match.
Afterwards, Federer said he had not expected to wait a year to play his Spanish rival again.
"After playing here last year you figured, maybe the French, Wimbledon or down the stretch in America at the latest we'll face off again, but it just never ended up happening," Federer said.
"It shows how incredible our last few years have been and I think it's exciting for tennis and for us obviously that we can face off again."
Earlier, Almagro showed superior speed and power to become only the second person this year to take a set off Nadal on clay.
But the four-time French Open champion raised his game to break in the fourth game of the second set before closing out the match in ruthless fashion.
After a stunning performance in the first set, in which he broke the Nadal serve three times, Almagro's head seemed to drop after going 3-1 down in the second.
Nadal broke again in the eighth game to level the match before racing into a 3-0 lead in the decider.
Almagro rallied to win his next two service games to stay in the match but a string of booming forehands saw Nadal home.
"The match was very close to getting away from me in the second set," said Nadal.
"Getting into another final is a huge joy. It's been a long spring season on clay and being in this final is a dream."
Almagro has now lost all six of his meetings with Nadal and said: "The way I was playing at the start was the way I had to play. I'll have to keep working and maybe sooner or later I can manage to beat Rafa."
The win stretched Nadal's unbeaten run on clay to 14 matches this year, a run that included titles in Monte Carlo and Rome, and also restores his status as world number two.
Victory in Sunday's final would be Nadal's record 18th title in a Masters Series event, one more than Federer and Andre Agassi.
It would make the 23-year-old firm favourite to reclaim the French Open title at Roland Garros in Paris on 23 May.
Nadal won the title four years in a row before suffering a surprise defeat to Sweden's Robin Soderling in the fourth round in 2009.