Jayawardene, 37, hit 16 fours and a six in his nearly six-hour stay at the wicket to pull up Sri Lanka from a shaky 16-2 after the hosts opted to bat on a docile track at the SSC ground.
This was Jayawardene's 11th century at the ground, the most by any batsman at a single venue. He also joined India's Sunil Gavaskar and Brian Lara of the West Indies at tied fifth on the list of highest Test century makers.
Mathews, who promoted himself up the batting order, played patiently before nicking to wicketkeeper Quinton de Kock off part-time spinner Jean-Paul Duminy shortly into the final session.
Kithuruwan Vithanage, playing his fifth Test and first against South Africa, was peppered with short balls by the quicks until his misery was ended by seamer Morne Morkel (1-42) who had him caught by AB de Villiers for 13.
Test debutant Niroshan Dickwella, batting on 12 at stumps, was given out caught off Duminy but the decision was revoked on review with TV replays showing the ball had hit only his pads.