Euro 2012 qual. - Late Llorente goal sinks Scots
Craig Levein's side fell 2-0 behind on 55 minutes when Andres Iniesta added to David Villa's 44th minute penalty for the visitors.
Scotland were soon back on level terms courtesy of a superb passage of play.
The Scots sensed a famous win, but were undone when Llorente emerged unmarked at the back post to rattle home Joan Capdevila's cross 11 minutes from time.
The game had already slipped away from the Scots by that late stage.
Rangers goalkeeper Allan McGregor enjoyed an outstanding match for the home side, but Scotland will feel aggrieved not to claim a point from the match after producing a second half performance of some intensity, and no little quality.
Spain top Group I on nine points from three games with Villa joining Raul as his country's top goalscorer on 44 goals.
Levein was widely berated for visiting the Czech Republic on Friday and playing with no forwards in a 1-0 loss in Prague.
Such a stirring performance against the defending European and world champions will not exactly stifle those critics, but at least Scotland have a measure of pride back if nothing else.
The Scots forced a corner kick in the opening seconds when Miller's cross was walloped out by Pique.
It was to prove a rare moment of glee as the visiting side enjoyed 67% of possession and over 12 shots the home goal in the first period.
Scotland were cut open like a knife going through hot butter on 12 minutes when Xabi Alonso picked out Villa, whose snapshot from 12 yards flew just over.
Villa was again to the fore two minutes later as he nodded David Silva's cross at goal only to find the grateful arms of McGregor.
Spain were producing the type of play that saw them crowned world champions in July as several players combined to some effect with one-touch play, but McGregor was equal to the task to save from Silva as he prodded at the home goal from inside the box.
Scotland produced their best moment of the half on 17 minutes as Morisson won space in the Spanish box only for Joan Capdevila to throw a leg in front of the Scottish midfielder's shot.
Alonso was pulling the strings in the midfield for Spain as Silva's control let him down when he was picked out by the Real Madrid player.
Spain finally scored the opening goal on 43 minutes when Whittaker was deemed to have handled from Ramos and Villa just prodded the ball beyond McGregor as he dived to his left.
Spain picked up from where they left off as Iniesta thumped the ball home on 55 minutes for his first goal since the World Cup final before the home side recovered in rousing fashion.
Miller picked out Rangers team-mate Naismith who dived to convert a diving header from five yards before Fletcher played inMorisson, whose cutback was knocked into his own net by Pique.
Despite the passion of over 50,000 home fans, Llorente on for Silva only three minutes earlier, applied the dagger to Scottish hearts when he rattled the ball into the back of the net with Stephen McManus and David Weir caught out in the middle of their own box.
Scotland can still secure second place and a play-off spot from the section, but they must secure maximum points from home games against the Czech Republic and Lithuania at home and an away match in Liechtenstein next September and October.
They will need to reach 13 points for second spot, but only have four from their opening four games.