Sri Lanka, who were reduced to 86-5 before lunch in reply to South Africa's 361, recovered to post 210-7 by tea on the second day at the Sara Oval on Saturday.
Chaminda Vaas was unbeaten on 14 and Farveez Maharoof was on four with Sri Lanka still 151 runs behind with three wickets in hand.
Kapugedera, a 19-year-old playing his fourth Test, smashed nine boundaries and two sixes in 63 off 77 balls.
Wicket-keeper Jayawardene, who took over the gloves from Kumar Sangakkara in this series, made 42 with six fours and a six in his seventh match.
Both batsmen, however, departed in the space of six deliveries late in the post-lunch session to hand the advantage back to South Africa.
Kapugedera was bowled trying to sweep left-armer Nicky Boje and Jayawardene had his stumps scattered by a fast Dale Steyn delivery.
South Africa are seeking a series-levelling win after being thrashed by an innings and 153 runs in the first Test at the Sinhalese sports club.
Earlier, South Africa's pace spearhead Makhaya Ntini destroyed Sri Lanka's top order with a four-wicket haul in the morning session.
The Sri Lankan reply contrasted sharply with their display in the first Test where captain Mahela Jayawardene hit the fourth highest score of 374 after sharing a world record stand of 624 with Kumar Sangakkara (287).
Ntini struck in his second over when Upul Tharanga mistimed an attempted hook shot and the ball ballooned to Nicky Boje at mid-on.
Sangakkara, who batted close to 11 hours in the first Test, lasted only 31 deliveries to score 14 when he flicked Ntini to short mid-wicket where Hashim Amla took an overhead catch.
Skipper Jayawardene repeatedly slashed outside the off stump in his brief knock of 13 when another dangerous swish against Steyn found the edge to wicket-keeper Mark Boucher.
Ntini returned for his second spell just before lunch to remove Tillekeratne Dilshan and opener Sanath Jayasuriya in the space of three deliveries.
Dilshan was bowled off the inside edge for four and Jayasuriya, who made 47, edged an outswinger to Herschelle Gibbs at second slip.