Jayawardene joined Indian Sunil Gavaskar and West Indian Brian Lara with 34 test centuries, reaching the milestone in the final over before tea when he swept a Dean Elgar full toss and ran for two.
The right-hander hit 13 boundaries and a six in his unbeaten 101, having added 97 runs with skipper Angelo Mathews (48 not out) in the second session that belonged to the hosts.
The South African bowlers toiled on a unresponsive batting pitch at the Sinhalese Sports Club without any success as Sri Lanka added 97 runs in that session.
Jayawardene earlier completed his chanceless half-century in an eventful morning session to help Sri Lanka overcome Dale Steyn's double strikes.
Steyn, man-of-the-match in South Africa's 153-run victory in the first test at Galle, rocked Sri Lanka early, sending back Upul Tharanga for 11 and Kumar Sangakkara for a golden duck with short pitched deliveries.
Tharanga gloved a catch to de Kock failing to get away from a rising delivery ball and Sangakkara fluffed his pull and top edged to give Imran Tahir a simple catch at square leg.
It was the left-hander's fifth golden duck of his career and 10th overall.
South Africa then captured the wicket of Kaushal Silva (44) in the last over before lunch when the batsman edged a JP Duminy delivery to AB de Villiers at slip to depart after his 99-run stand with Jayawardene.
The opener got a life on nine when Alviro Petersen dropped him at third slip and also at 17 when he edged Duminy between wicket-keeper Quinton de Kock and slip fielder de Villiers.