The spin wizard struck either side of tea Sunday as the tourists slumped from 161-3 to 257-7 in their second innings at stumps, an overall lead of 297 with three wickets in hand.
South Africa have the advantage of bowling last on a wearing Sara Oval wicket as they seek a series-levelling win after being thrashed by an innings and 153 runs in the first Test.
Sri Lanka, however, will fancy their chances against the pace-dominated South African attack that contains just one spinner in left-armer Nicky Boje.
"We have never won a Test match chasing more than 330, but I think we can win this one," said captain Mahela Jayawardene.
"It's a fast outfield and our batsmen are in form. I am pretty happy with the situation because we did not allow the game to slip away."
South African opener Herschelle Gibbs returned to form with 92, but his dismissal by Muralitharan at the stroke of tea triggered a collapse that left the enthralling Test match in the balance.
Gibbs lost his concentration after a four-hour vigil under a hot sun and swept Muralitharan to Sanath Jayasuriya at backward square leg in the last over before tea.
Gibbs, who made 19 and 18 in the previous match and was dismissed second ball in the first innings here, fell eight runs away from his 15th century after showing glimpses of his old form.
"I think spin will play a big part in the match," said Gibbs. "It was good to be back among the runs again but we still need another 50 runs. A lot will depend on how we bowl with the new ball."
Muralitharan, who claimed 10 wickets in the first Test and five more in the first innings here, returned after tea to dismiss captain Ashwell Prince and A.B. de Villiers in the space of four deliveries.
Prince plodded for two hours to make 17 and then patted an easy return catch to the bowler, while de Villiers was snapped up by Tillekeratne Dilshan for 33.
Shaun Pollock, who hit an unbeaten 57 in the first innings, made 14 before pulling Muralitharan straight to Upul Tharanga at square leg.
Muralitharan, who ended the day with 4-86, now has 654 Test wickets, second behind Australian record-holder Shane Warne's tally of 685.
Gibbs and Andrew Hall (32), who resumed on the overnight score of 6-0, put on 76 for the first wicket before South Africa slipped to 131-3.
Left-hander Jacques Rudolph put on 43 for the second wicket with Gibbs before being run out for 15 amidst controversy and confusion on the field.
When Malinga's leg-before appeal against Gibbs was turned down by umpire Billy Bowden, the batsmen took off for three runs as the ball raced to the fine-leg region.
Tharanga dived near the boundary to stop the ball and rifled in a direct hit to break the striker's wicket with Rudolph short of his crease.
Square-leg umpire Aleem Dar consulted television umpire Tyronne Wijewardene on whether Tharanga had fielded the ball cleanly near the boundary.
When Wijewardene ruled in favour of the fielder, he was also asked to give a verdict on the run out. Television pictures showed Rudolph well short of his crease and Dar raised his finger.
As the Sri Lankans celebrated, Rudolph stood his ground since the South African dressing room indicated Tharanga had touched the rope while fielding the ball and the umpires should award four runs.
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: 321 (C. Kapugedera 63, F. Maharoof 56, C. Vaas 64, D. Steyn 5-82, M. Ntini 4-84)
South Africa 2nd innings (overnight 6-0):
Fall of wickets: 1-76, 2-119, 3-131, 4-161, 5-206, 6-207, 7-235
South Africa lead by 297 runs