Heroes were strewn around the Caja Mágica in various states of disappointment and joy on Saturday but one stood a little taller in Great Britain’s defeat. Kyle Edmund, who has inspired them all week, led his teammates to the brink of their second Davis Cup final in four years, by word and deed, ignoring the seriously late replacement of Pablo Carreño Busta with Spain’s seasoned left-hander, Feliciano López, whom he then tamed in straight sets. It was majestic, but it was not enough.

Almost inevitably, it was Rafael Nadal who spoiled the party for the 2015 champions, beating Dan Evans in the second rubber 6-4, 6-0, then joining López to outlast Jamie Murray and Neal Skupski in the deciding doubles 7-6 (3), 7-6 (8). The match was close throughout, Nadal saving set point on his own serve to force the second tie-break after two hours, and generated as much heat on the court as off.

The Spanish were livid with a dubious call against them at 2-2 in the second shootout, especially so Nadal, who had been up until 1am in a doubles match the previous night. The Spaniards reined in their emotions, saved four set points and failed to cash in on a first match point before López served out at the second opportunity for a gripping win.

Nadal, ecstatic and exhausted, said: “This competition is dramatic, and with this new format even more. It had been close. We weren’t able to have one break in the whole match. Feli served amazing. In the important moment he did everything well. We are super, super happy. An amazing, unforgettable evening for all of us.”

Earlier, Edmund said after beating López 6-3, 7-6 (3) in an hour and 20 minutes that he found out only five minutes beforehand that he was replacing Busta.

“Busta came to warm up on the bike,” Murray said. “After two minutes, he left. I said straight away, ‘Something is a bit weird there.’ I think they knew what was going on but they went to the rules [which demanded an independent medical opinion on Busta’s leg injury]. They could do that. There’s no point trying to argue it.

“I was good within myself, where I was at, how I was feeling. I was just enjoying going out to the semi-finals of a Davis Cup against Spain. I knew it was going to be loud. It almost didn’t matter who I was playing, I was just concentrating on being me first and putting myself out there.” He thumped nine aces, eight of them in the first set.

After a close, thrilling doubles main course, played out again raucous support from both sides, Spain celebrated their seventh win over Great Britain in 15 Davis Cup ties, and are now pitched into one last examination of their resolve, against Canada in Sunday’s final.

The Canadians earlier wrote their own grand tale to reach the final for the first time when, having used only two players all week in Vasek Pospisil and Denis Shapovalov, they were too strong for the Russians, who similarly had called on only two players for the entire tournament, Karen Khachanov and Andrey Rublev.

Denis Shapovalov and Vasek Pospisil have taken Canada into the final. Photograph: Europa Press Sports/Europa Press via Getty Images

It has been that sort of crazy experience, rebranded as the World Cup of Tennis by the Barcelona footballer Gerard Piqué and his marketing team. The enthusiasm pulsed at different levels from Monday to Saturday. Some matches were electric, others finished ridiculously late, there were comical glitches on the website and app, and a general sense that too much was being poured into a small boat on rough seas.

Nevertheless, the greatest passion erupted when Spain played Great Britain. It was as if the Last Night at the Proms had moved to Madrid for one evening. Andy Murray, resting his wounded body, had sent out word on Instagram for British supporters in the Spanish capital to roll up for free tickets; 975 of them obliged, and, while disappointed by the result, they could hardly complain about the entertainment.

Evans, who had helped the team into the semis with a courageous three-set win over Germany’s Jan-Lennard Struff on Friday, found Nadal an altogether different proposition in the second rubber. “Our mantra, whatever you want to call it, is to fight until the end,” he said. “I thought I did that pretty good. Everybody who stepped out on the court this week for Great Britain’s done that, win or lose.”

He did not shrink from accusing Spain of gamesmanship, though. “It’s a little naughty, I’d say. That independent doctor comes in and said Carreño was not fit to play? Interesting, isn’t it? When we saw Carreño at the end of [Friday’s] match, I didn’t think he was fully fit. To be honest, if you name a team, we just think that’s going to be the team. It was a surprise when López came in. But I thought Kyle did an unbelievable job dismantling him.”

They all took victory and defeat equally well, just the same, preferring to leave Madrid with the good memories rather than dwell on those they enjoyed less.

“I’m sure he won’t mind me saying, but what he’s done in the last two months has been extraordinary, to get himself back,” Evans said of Edmund. “I’ve seen it first-hand. He’s worked hard. And to turn it around in Paris and keep going where people could have just stopped the year, and then get picked to play and what he’s done here, he’s looked basically back to top-20 player again. It’s great to be on his side.”

Edmund has been the reborn hero of British tennis, looking strong and commanding from the moment he replaced Andy Murray for the second tie, against Kazakhstan. The player whose season looked to be shredded beyond repair when he lost eight matches in a row before the recent Paris Masters and had tumbled to No67 in the world, has found his inner tiger at last.