Rafael Nadal inspired Spain into their first Davis Cup final since 2012 as he teamed up with Feliciano Lopez to secure a dramatic last-four victory over Britain in Madrid.

The hosts trailed 1-0 after Lopez's singles defeat by Kyle Edmund on Saturday, but Nadal thrashed Dan Evans before partnering Lopez in a 7-6 (7/3), 7-6 (10/8) win in the deciding doubles over Jamie Murray and Neal Skupski.

Spain will face Canada in Sunday's final after the North Americans won their semi-final against Russia, which was also decided in the doubles rubber.

"It was a very special moment for us, a very unique opportunity," said the 38-year-old Lopez. "We have a great opportunity to win this tournament here at home."

Denis Shapovalov and Vasek Pospisil sent Canada into their maiden Davis Cup showpiece by edging out Karen Khachanov and Andrey Rublev.

Five-time champions Spain were indebted to world number one Nadal for a virtuoso display as the 33-year-old continues his hunt for a fifth Davis Cup crown, having first lifted the title himself in 2004.

"This competition is always dramatic, especially with the new format," said Nadal.

Canada reached their first Davis Cup final
Canada reached their first Davis Cup final AFP / JAVIER SORIANO

"It's really, really special. Thank you to Feli (Lopez) and to the crowd who were amazing as well."

Spain lost their last Davis Cup final to the Czech Republic six years ago.

Edmund had earlier justified the decision of British captain Leon Smith to select him ahead of three-time Grand Slam champion Andy Murray by seeing off Lopez 6-3, 7-6 (7/3).

But Nadal swatted aside Evans 6-4, 6-0 to set up the doubles showdown.

Murray and Skupski more than held their own in the face of a partisan home crowd and a pumped-up Nadal at the Caja Magica, but saw a break point come and go in the 11th game of the first set before losing a tie-break.

The Britons saw four set points pass them by in the second set, including three in the breaker, with Nadal saving one by producing an incredible lob on the stretch.

A place in the final was sealed on a second match point.

"Rafa (Nadal) plays like this from the first round in every tournament. It's one of his powers," said Spain captain Sergi Bruguera.

Nadal and Lopez celebrate a dramatic victory
Nadal and Lopez celebrate a dramatic victory AFP / Oscar DEL POZO

Earlier on Saturday, the 20-year-old Shapovalov had drawn Canada level by beating Khachanov after Rublev's win over Pospisil in the opening match.

The Canadian pair then edged out Khachanov and Rublev in a thrilling deciding-set tie-break.

"I thought both teams played phenomenal," Canada captain Frank Dancevic said.

"The Russians threw everything they had at us, it was just a matter of who came up with the better shots. There was no room for error today -- they went for their shots, went big in the big moments, and here we are into the final."

It was their third Davis Cup semi-final, after previous last-four defeats in 1913 and 2013.

"We've got a huge day, a historic day for us tomorrow, and we're going to leave it all out there," said world number 150 Pospisil.

Canada secured a 6-3, 3-6, 7-6 (7/5) victory on their second match point to finish a tie which lasted six and a half hours.

Earlier, Shapovalov had seen off Khachanov, Russia's leading player in the absence of world number four Daniil Medvedev due to exhaustion, in a dramatic match.

The left-handed rising star, who reached his maiden Masters final in Paris earlier this month, saved three successive break points while serving for the match.

The in-form Rublev had made it four singles wins from as many matches this week by brushing aside Pospisil 6-4, 6-4.

Canada have reached the final despite being without the injured Felix Auger-Aliassime, the world number 22, with Pospisil stepping up instead.

"I'm at a loss for words," Shapovalov said. "It's incredible how far we've come this week, with me and Vasek playing on a different level.

"It's unbelievable to see. And to clinch it like this, in the doubles, I wouldn't have it any other way."