The Seville winger walked in Andres Iniesta's clever pass two minutes from time to break Croatia hearts and ensure the champions top Group C.
The world champions could now play England or France in the last eight.
The landscape of the group might have been so different had Croatia scored the goal they had threatened to for long periods of the second half, however.
On a night of tension and frustration in Gdansk, Slaven Bilic's men stretched their more celebrated opponents time and again with Luka Modric tormenting the Spanish midfield with a vibrant, menacing performance.
The Tottenham Hotspur midfielder created the best chance of the match for Croatia on the hour mark, finding Ivan Rakitic from a scintillating cross delivered with the outside of his right boot which the Seville midfielder could only head directly at Spain goalkeeper Ilker Casillas.
Spain march on, however, now unbeaten in 17 competitive matches. But this was a performance that epitomised their faltering progress here: style but no substance, beauty but no brawn, panache but no penetration.
Much of the talk before the game had centred on Italy's fear that Spain and Croatia would contrive a 2-2 draw - a result that would have ensured both teams qualified for the quarter-finals at the Azzurri's expense.
And for much of the opening 45 minutes, Croatia were outpassed, if not outclassed. But they stood firm, with the twin towers of Vedran Corluka and Gordon Schildenfeld at the heart of the defence epitomising Croatia's spirit and refusal to yield.
They could not, though, prevent Xavi from gradually getting Spain moving. Fernando Torres saw a fierce low shot turned away by Stipe Pletikosa after 22 minutes before David Silva and Iniesta twice almost linked up to devastating effect.
- Relief as surgeons re-attach man’s severed private organ
- Can medical board really bite finger that feeds it?
- Mother claims nurse watched her newborn die
- Governor’s encounter with leaky roofs in school
- Police arrest former councillor for piracy
- Cord leaders allege ploy by State to ‘kill’ devolution through Ministry