A gripping semi-final saw the singles split and the tie came down to drama in the doubles on Sunday (AEDT).
The Spanish duo, in front of a partisan crowd in Madrid, survived a major test as Nadal and Lopez needed two tie-breaks to fend off Jamie Murray and Neal Skupski.
With Andy Murray roaring on the British team from courtside, his older brother and Skupski pushed Nadal and Lopez through two intense sets before falling just short, losing 7-6 (7-3) 7-6 (10-8).
The British pair had set points to take it to a decider, but Spain, and Nadal in particular with one sublime overhead after a brilliant reach, produced its best when the pressure was at its greatest.
It was always likely Great Britain would need Kyle Edmund to win his singles rubber and he duly delivered with a 6-3 7-6 (7-3) win against Lopez — a late stand-in for the injured Pablo Carreno Busta.
But Nadal coasted to a 6-4 6-0 beating of Dan Evans, who tailed off after putting up a valiant effort in the first set against his more illustrious opponent.
After the late-night doubles joy, with the contest finishing well after midnight, Nadal said: "I think we played a great match. 'Feli' served great the whole match and at important moments he did everything well.
"Thank you very much to Feli and the rest of the team."
Lopez said: "There was a lot of drama today on the court. We are very pleased we somehow managed to play those points in a very good way.
"It was a lot of drama but this is what you expect when you play this kind of match. I think we have a very good opportunity tomorrow to lift this cup."
Earlier, Canada reached the Davis Cup final for the first time in their history by winning a similarly thrilling tie against Russia.
Denis Shapovalov kept Canada in with a chance by beating Karen Khachanov 6-4 4-6 6-4 after Andrey Rublev overcame Vasek Pospisil 6-4 6-4.
The Canadian duo defeated its Russia rival 6-3 3-6 7-6 (7-5) in a thrilling deciding doubles rubber.