Sri Lanka, set 352 to win, lost three wickets for nine runs to slip to 350-9 after lunch on the fifth day before last man Lasith Malinga drove Nicky Boje for the winning run on Tuesday.
Sri Lanka swept the short two-Test series against the depleted tourists missing the injured duo of captain Graeme Smith and leading all-rounder Jacques Kallis.
The home side had won the first Test by an innings and 153 runs at the Sinhalese Sports Club (SSC) last week.
It was Sri Lanka's most successful fourth innings chase, surpassing the 326-5 they made to defeat Zimbabwe at the SSC during the 1997-1998 season.
Sri Lanka, who were just 19 runs away from victory at lunch with four wickets in hand, were kept in the field for an hour after resumption by the South Africans amidst growing tension at the Sara Oval.
With 11 needed, Jayawardene stepped out to Boje and edged a catch to Herschelle Gibbs in the slips. It was the left-arm spinner's 100th Test wicket in 43 matches.
Seamer Andrew Hall had Chaminda Vaas caught superbly in the slips by A.B. de Villiers and then clean-bowled Muttiah Muralitharan, leaving Malinga to deliver in the company of Farveez Maharoof.
Maharoof levelled the score with a single off Boje before Malinga drove the next ball to the vacant mid-on region to seal a close win.
Boje finished with four for 111, while Hall took three for 75.
Jayawardene, dropped by Gibbs at gully off Hall when he was on two on Monday, showed the touch that brought him the fourth highest Test score of 374 in the first Test.
The 83-Test veteran hit 11 boundaries and two sixes in his 16th Test century, having anchored the innings for six hours.
The 29-year-old had put on a world record partnership of 624 with Kumar Sangakkara (287) in the first Test, helping Sri Lanka reach 756-5 declared.
Maharoof escaped two chances in one over from Boje to remain unbeaten on 29, having put on 62 for the seventh wicket with Jayawardene.
Maharoof missed being stumped by Mark Boucher on one and, two balls later, Hashim Amla dropped a chest-high catch at silly point.
Sri Lanka, who began the day needing 90 to win, had added 17 runs to their overnight total of 262-5 when Hall trapped Prasanna Jayawardene leg-before for 30.
The young wicket-keeper departed after adding 78 for the sixth wicket with his captain.
The tourists were handicapped by the absence of pace spearhead Makhaya Ntini due to a hamstring injury.
Ntini, who bowled 44 deliveries at half pace on Monday, did not take the field on Tuesday, leaving Shaun Pollock to share the second new ball with Dale Steyn.
Sri Lanka's win was set up by spin wizard Muralitharan, who claimed 12 wickets in the match to equal his own world record of four consecutive 10-wicket hauls.
Muralitharan grabbed 22 wickets in the two Tests to take his tally to 657, second only behind Australian record-holder Shane Warne's 685.
Sri Lanka and South Africa will now be joined by India for a limited-overs tri-series in Colombo from August 14-29.