The duo put on 105 for the sixth wicket after a four-wicket haul by South African pace spearhead Makhaya Ntini reduced the hosts to 86-5 before lunch Saturday on the second day at the Sara Oval.
Veteran Chaminda Vaas (64) and Farveez Maharoof (56) continued the fightback by adding 117 for the eighth wicket as Sri Lanka were bowled out for 321 in reply to South Africa's 361.
The tourists, 40 runs ahead on the first innings, were six for no loss in their second knock at stumps with Herschelle Gibbs on four and Andrew Hall on two.
South Africa, seeking a series-levelling win after being thrashed by an innings and 153 runs in the first Test, lead by 46 runs with all 10 wickets in hand in an absorbing battle between bat and ball.
"We are back in the game," said Sri Lanka's Australian coach Tom Moody. "We were a bit down at one stage but I was not surprised at how well the lower order fought.
"Chamara is a real talent and it was good to see Prasanna stick it out there. Then Vaasy played like the experienced player he is and Maharoof improved as he went along.
"We need to keep the South Africans down in the second innings. There is a lot to play for over the next three days."
Seamer Dale Steyn finished with five for 82 and Ntini claimed four for 84 to help South Africa secure the lead.
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 Steyn delivery.
Vaas and Maharoof pushed the South Africans back with superb strokeplay on both sides of the wicket before Steyn removed both batsmen with the second new ball.
Steyn clean bowled Maharoof, had Vaas caught down the leg-side by wicket-keeper Mark Boucher before forcing last man Muttiah Muralitharan to give a catch at mid-on.
"It was a long day out in the sun," said Steyn. "But it is very encouraging to get the lead and I am sure we will build on that."
Sri Lanka's top order setbacks 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 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 Gibbs at second slip.
South Africa 1st innings: 361 (A. Prince 86, A.B. de Villiers 95, S. Pollock 57 not out, M. Muralitharan 5-128, L. Malinga 3-81)
Sri Lanka 1st innings:
Fall of wickets: 1-16, 2-42, 3-74, 4-85, 5-86, 6-191, 7-191, 8-308, 9-317
South Africa 2nd innings:
South Africa lead by 46 runs