Kumar Sangakkara smashed his 49th half-century as Sri Lanka launched a fightback on the fourth day of the first Test against South Africa on Saturday.
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 Lanka 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.
But a sporting declaration by South Africa's new 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.
South Africa began their defence well, with Dale Steyn once again giving his side the early breakthrough by dismissing opener Upul Tharanga for 14.
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 mid-wicket for a four.
Silva also knocked off some easy runs, smacking part-timer Jean-Paul Duminy for two fours in a row.
Earlier, AB de Villiers hit six boundaries in his breezy 58-ball 51 and also shared 62 runs with Quinton de Kock (36) to set up South African second innings.
The Proteas had made 455-9 declared in their first essay.
The second and final Test will be played in Colombo from July 24-28.