Jayawardene's marathon innings, the highest ever score by a Sri Lankan and the fourth highest in the all-time individual innings list, guided his team to a formidable 756 for five declared.
The host's massive score, the second largest in history by Sri Lanka, left South Africa facing a daunting 587-run deficit with 6-1/2 sessions left in the game.
However, the tourist's long fight for survival started well with openers Andrew Hall (13 not out) and Jacques Rudolph (24 not out), standing in for the indisposed Herschelle Gibbs, finishing on 43 without loss at the close.
Jayawardener compiled a 624-run stand spanning 160.3 overs with left-hander Kumar Sangakkara before Andrew Hall finally found the outside edge of the latter's bat with a full-length reverse-swinging delivery.
The previous 576-run record set by compatriots Sanath Jayasuriya and Roshan Mahanama against India in 1997 was broken as wicketkeeper Mark Boucher conceded four byes down the leg side off the bowling of left-arm spinner Nicky Boje.
Celebrated with firecrackers around the Sinhalese Sports Club Ground, the new milestone was reached with Jayawardene on 278 and Sangakkara on 273. The partnership was also the highest ever stand in first-class cricket.
When he was finally bowled by an Andre Nel delivery that kept low, the 29-year-old Jayawardene, who also passed 6,000 Test runs during his innings, had faced 572 balls hit a total of 43 boundaries and one six.
His elegant innings was all the more remarkable for the fact that he did not offer South Africa's fielders a single chance and was only rarely beaten, his biggest scare before his eventual downfall being a lbw appeal from Makhaya Ntini that was slipping down the leg side.
CARNIVAL ATMOSPHERE
The crowd had swollen throughout the afternoon as spectators sensed an opportunity to watch Jayawardene break Brian Lara's record Test score of 400. But the carnival atmosphere was punctured when his off stump was knocked back shortly after South Africa took the second new ball.
The previous highest score by a Sri Lankan was the 340 scored by Jayasuriya against India in 1997 at Premadasa International Stadium.
Jayawardene and Sangakkara also became only the second pair in Test history to score 250's in the same innings after Gary Sobers and Conrad Hunte for West Indies against Pakistan in 1957-58.
Sangakkara's 287, also a personal best after his 270 against Zimbabwe in 2004, spanned a total of 457 deliveries and included 35 boundaries.
Middle order batsman Tillakaratne Dilshan, forced to wait over 11 hours with his pads on the in the dressing room, assisted Jayawardene with an industrious 45 during a fourth-wicket stand that yielded 113 runs.
Paceman Dale Steyn proved the most successful bowler, claiming three for 129 from 26 overs, but it was left-arm spinner Nicky Boje who provided the greatest threat throughout the innings.
However, despite maintaining a disciplined line and turning the odd ball sharply, Boje finished wicketless with 0-221 from 65 overs of hard toil.
Scorecard:
South Africa 1st innings 169 (A. de Villiers 65; M. Muralitharan 4-41, D. Fernando 4-48)
Sri Lanka 1st innings (Overnight: 485-2)
U. Tharanga c Boucher b Steyn 7
S. Jayasuriya lbw b Steyn 4
K. Sangakkara c Boucher b Hall 287
M. Jayawardene b Nel 374
T. Dilshan lbw b Steyn 45
C. Kapugedera not out 1
Extras (b-17 lb-5 nb-8 w-8) 38
Total (for 5 wickets declared, 185.1 overs) 756
Fall of wickets: 1-6, 2-14, 3-638, 4-751, 5-756
Did not bat: P. Jayawardene, F. Maharoof, L. Malinga, D. Fernando, M. Muralitharan
Bowling
M. Ntini 31 - 3 - 97 - 0 (nb-1)
D. Steyn 26 - 1 - 129 - 3 (nb-6 w-2)
A. Nel 25.1 - 2 - 114 - 1 (nb-1 w-1)
A. Hall 25 - 2 - 99 - 1
N. Boje 65 - 5 - 221 - 0
J. Rudolph 7 - 0 - 45 - 0
A. Prince 2 - 0 - 7 - 0 (w-1)
A. de Villiers 4 - 0 - 22 - 0
South Africa 2nd innings
J. Rudolph not out 24
A. Hall not out 13
Extras (nb-6) 6
Total (for no loss, 15 overs) 43
Fall of wickets:
To bat: H. Gibbs, H. Amla, A. Prince, A. de Villiers, M. Boucher, N. Boje, A. Nel, M. Ntini, D. Steyn
Bowling
L. Malinga 4 - 0 - 22 - 0 (nb-2)
F. Maharoof 3 - 0 - 9 - 0 (nb-3)
D. Fernando 3 - 1 - 2 - 0 (nb-1)
M. Muralitharan 4 - 1 - 10 - 0
T. Dilshan 1 - 1 - 0 - 0