The prolific left-hander also shared 96 runs for the unbroken second wicket with Kaushal Silva (37) to take Sri Lanka to 110-1 at stumps.
The hosts need 260 runs with nine wickets in hand to pull off a magical come-from-behind win with three full sessions left in the game.
"In a situation like this where you have 90 overs to bat, a win is not guaranteed but there is a chance," Sri Lankan coach Marvan Atapattu said after the day's play.
Sri Lanka had been forced on the backfoot after they were bowled out for 292 to concede a huge 163-run lead in the first innings.
Also Read
But a sporting declaration by new South African skipper Hashim Amla at the tea score of 206-6 turned the game on its head.
Although no team has ever scored more than 300 runs in the final innings at Galle, the 36-year-old Sangakkara made a target of 370 look chaseable.
The star batsman hit seven fours and a six in his 58-run knock that came off 89 deliveries.
But Sangakkara stood like a rock at the other end, once despatching a full-toss from Tahir over the mid-wicket fence for a huge six. He completed his half-century in style, sweeping leg-spinner Imran Tahir through midwicket for a four.
Silva also knocked off some easy runs, smacking part-timer Jean-Paul Duminy for two fours in a row.
- Amla fails with bat again -
=============================
"Look, they are very much in the contest, there's no doubt about it. But so are we," said South African coach Russell Domingo.