Great Britain put themselves in a promising position at the new-look Davis Cup finals by edging to a tense 2-1 victory over the Netherlands in their opening group tie.
Jamie Murray and Neal Skupski sealed the triumph with a 6-4 7-6 (8-6) win in the decisive doubles rubber.
That match became pivotal after Dan Evans lost to Robin Haase in Madrid.
Haase levelled the tie after Andy Murray said he "didn't deserve" to beat world number 179 Tallon Griekspoor.
But after Jamie Murray and Skupski beat Dutch pair Wesley Koolhof and Jean-Julien Rojer, Britain know victory against Kazakhstan in their second round-robin tie on Thursday (10:00 GMT) will put them in the quarter-finals as group winners.
"It was a hell of a long day but it was a really good atmosphere," captain Leon Smith said.
"The doubles was obviously a great performance, it was not easy playing in the deciding rubber. Jamie showed a lot of big experience and what Neal has managed to do on his debut is great. It's not easy doing what he's just done."
If captain Leon Smith's side lose against the Kazakhs - who are led by Mikhail Kukushkin and Alexander Bublik, players both well inside the world's top 100 - then they will finish runners-up.
However, they could still qualify for the last eight as one of the two best second-placed nations.
The nations would then be separated by the percentages of sets won, or possibly games won, in their group matches.
Eighteen nations are contesting a football-style tournament for the first time to determine the Davis Cup champions, with the winners of the six groups and the two best-placed runners-up reaching the quarter-finals.
Britain, who won the 2015 Davis Cup in the previous format, would have faced an uphill battle to reach the last eight in Madrid had they not beaten a Dutch side who lost their opening match against Kazakhstan on Tuesday.
Eventually they edged past the Dutch in a tie lasting almost nine hours to become the longest of the tournament so far.
11:00 local time: Players walk out on to court
14:09: Andy Murray wins 6-7 (7-9) 6-4 7-6 (7-5) against Tallon Griekspoor - Britain lead 1-0
17:00: Dan Evans leads but eventually loses 6-3 6-7 (5-7) 4-6 to Robin Haase - Netherlands level for 1-1.
19:44: Jamie Murray and Neal Skupski dig deep to win in straight sets - Britain win the tie 2-1
The outcome of the tie hinged on the success on 33-year-old Jamie Murray and Neal Skupski, his regular partner on the ATP tour but making his Davis Cup debut.
With the new format of the Davis Cup finals cutting ties from best-of-five rubbers to the best-of-three, the doubles always had the potential to become more pivotal in their outcomes.
That proved to be the case as Andy Murray's laboured win over Dutch world number 179 Griekspoor was followed by Haase's fightback from a set down against British number one Evans.
Murray and Skupski, 29, started aggressively against the Dutch pair Koolhof and Rojer, constantly asking questions of their service games while only dropping five points themselves as the teams were locked at 4-4.
Finally the British pressure told when Skupski drove a backhand down the line to clinch the break, sealing the opener only after fighting off five break points as Murray served for the set.
Murray and Skupski's level dropped as they trailed 4-1 and 5-2 in the second set before the pair won three games in a row for 5-5, then moved within a point of serving for the match as the Dutch scrabbled to save three break points.
Again momentum switched as Koolhof and Rojer created two set points in the tie-break, a net cord helping Murray and a fierce return from Skupski keeping them in the set.
Undeterred, the British pair continued to play positively and a neat pick-up from Skupski gave them a match point which they converted when Koolhof whacked a forehand wide, sparking jubilant celebrations among the British contingent.
Andy Murray took a tumble during the second set of his match
Former world number one Murray has not played a competitive match since winning the European Open title in Antwerp more than a month ago and he appeared to struggle physically at times against Griekspoor.
Murray revealed before the tournament he was at the heaviest weight of his career after taking a couple of weeks off to spend with his newborn son, adding after this win that he will not put himself "in that position again".
While far from appearing overweight in a sluggish first-set performance, it did contribute to a lack of match sharpness as he found the big-hitting Griekspoor hard to handle.
"I've never had that in my career before. It is something as you get older you need to keep a closer eye on," Murray said.
"I'll make sure when I do have breaks, I'm more careful with what I'm eating.
"If you're weighing four or five kilos more than you're used to, that is probably going to affect how you feel moving around the court. So I need to do better with that."
Asked whether Murray would play on Thursday despite "hurting" after this match, captain Smith said: ""We will have to have the discussion, see how everybody feels. We have great options."
Griekspoor, 23, may have only won two ATP Tour matches in his career but they came against three-time Grand Slam champion Stan Wawrinka and Russian world number 17 Karen Khachanov, illustrating his capability of causing problems for the very best.
Eleven aces and some impressive first-serve statistics in the mid-80s rocked Murray in the first set, before the Scot showed signs of improvement in the second - although far from his best - to level the match.
Twice Murray looked beaten in the final set, trailing 4-1 and again by the same scoreline in the tie-break, only to dig deep into his reserves to fight back.
Murray pointed to his heart as he celebrated, the gesture signifying the resilience which has helped him win the sport's biggest prizes and resurrect a career which even he thought was over after "life-changing" hip surgery in January.
Andy Murray said the atmosphere was "fantastic"
Barcelona footballer Gerard Pique has overseen the transformation of the 119-year-old competition into the season-ending finals, which has been met with fierce criticism from some and doubts about the atmosphere such a format would create.
While Spain's opening match on Tuesday night was unsurprisingly watched by a partisan and full crowd at the Caja Magica, some matches have struggled to attract spectators.
Britain's opening tie against the Dutch was not expected to be one and so it proved as about 1,000 Union Jack-clad fans created a boisterous atmosphere on a 2,500-capacity third show court which was about three-quarters full by most estimates.
"The atmosphere was one of the things players were worried about in a neutral venue but both sets of fans were fantastic," Andy Murray said.
However, with both Murray and Evans playing three sets before the doubles match, it meant the tie ended up lasting almost nine hours, leading to another scheduling nightmare for organisers and players.
After starting at 11:00 local time (10:00 GMT), Britain clinched victory through Jamie Murray and Skupski at 19:45 in the Spanish capital - with the second tie on the Caja Magica's third court between Belgium and Australia still to start.
That came after host nation Spain's match against Russia on Tuesday finally finished about 01:30 local time the following morning.