The defeat means that England lose their status as the world's best Test team to the tourists, having risen to the top a year ago with a 4-0 series win over India.
A loss on day five looked likely from the start of play: England were chasing the highest fourth-innings target in their history, and a new record of 346 runs for a Test at Lord's.
The early losses of Ian Bell and James Taylor, run out by Jonathan Trott in a farcical mix-up as they attempted to run four, left it more unlikely still at 45 for four.
But three half-centuries from Trott, Jonathan Bairstow and Matt Prior kept hopes alive.
In a scintillating spell after tea, England laid siege to South Africa before the second new ball, and suddenly the odds appeared to tilt in their favour. But when Prior finally fell for 73 to Vernon Philander, who took five wickets for 30 in the innings, the game, the series and their ranking were gone.
Already two wickets down with just 16 on the board when play began, England set about attacking with almost reckless intent. Trott, normally so defensively-minded, played some risky shots and missed several of them, but survived.
Bell, without adding to his overnight score, did not - flashing the bat at a Philander delivery which swung away from him, leaving Graeme Smith a catch which he grabbed at the second attempt.
Taylor followed soon after, though he had Trott to blame for his demise. Having run three, it was Taylor's call to run to the danger end, but Trott simply stayed put, and South Africa could scarcely believe their luck.
Trott continued with the South Africans chirping in his ear, but he was assisted by Bairstow, who finally gave England some momentum on day five. His innings was chancy but electric, and the pair put on 75 runs in 14 overs before lunch.
Bairstow was bowled by Imran Tahir shortly after reaching his half-century, and Prior began slowly by comparison. Trott fell 12 runs into their partnership, leaving the target once more looking a long way away.
England's tail have not chimed in with runs in the way they have in previous series, but here they attacked, with Stuart Broad the next to chance his arm, hitting a huge six over midwicket in a 42-ball innings of 37.
Broad holed out to Amla, who capped his superb series with a splendid steepling catch, but England only accelerated with the arrival of Swann.
At 221 for seven at the tea interval, England were, as they had been all day, the clear second-favourites, but an onslaught from Swann and Prior changed that.
They added 60 runs in 52 balls before Swann took a chance too many and was run out by Tahir.
Still the drama was not over - Prior remained at the crease - and those with a belief in fate must have wondered if it was written in the stars when Prior holed out to Morne Morkel, caught in the deep by JP Duminy, only to be recalled when it was shown that the bowler had no-balled.
Prior was just a whisker away from being stumped too as he looked to swat Tahir away for more runs, but it was once the second new ball was taken that England's chances of a famous upset were finally quashed.
Philander drew the edge from Prior from his fourth delivery with the new ball, then repeated the trick with Steven Finn with the next.
England went into the series with high hopes of cementing their status as the world's best Test side - instead, they have spent the three Tests bogged down by controversy over Kevin Pietersen's future and being for the most part outclassed by their visitors.
Captain Andrew Strauss and coach Andrew Flower are left with plenty to ponder ahead of a challenging four-Test tour of India, which starts in November.
Mark Patterson - on Twitter @Mark_Eurosport
- Jonathan Trott