A maiden Test hundred by Ibrahim Zadran helped Afghanistan recover in the one-off Test against Sri Lanka in Colombo, as the tourists ended day three on 199-1 on Sunday.
Afghanistan showed fight after being shot out for 198 in their first innings to concede a lead of 241.
Ibrahim went past his previous best Test score of 87 and then completed his maiden Test hundred in the last over of the day with a single to covers, finishing unbeaten on 101.
It is only the fourth Test hundred by an Afghan though the 22-year-old opening batsman was given two reprieves.
The first was on 39 when Prabath Jayasuriya put down a tough return catch, and then again on 63 when Nishan Madushka at short mid-off dropped a catch off Jayasuriya's bowling.
A record 106-run stand for the first wicket between Ibrahim and Noor Ali Zadran set the platform for Afghanistan's second innings.
That improved on the 53-run stand between Ibrahim and Javed Ahmadi against West Indies in 2019.
After tea, Asitha Fernando tested the batters by reverse swinging the ball and dismissed Noor Ali for 47 when he trapped the debutant leg before wicket.
It was a much-needed breakthrough for Sri Lanka, having failed to pick up a wicket in the afternoon session.
Allrounder Rahmat Shah, the top scorer in the first innings, then joined Ibrahim and added an unbroken 93 runs for the second wicket. He was 46 not out.
Kasun Rajitha was drafted into the side after debutant fast bowler Chamika Gunasekara was hit on the helmet by a nasty Naveed Zadran delivery.
Sri Lanka earlier resumed on their overnight total of 410-6 and were bowled out for 439 as they lost their last four wickets for 12 runs.
"Afghanistan, we know, do not have a proper place to train... and the players are spread across the world," said Sri Lanka's Dinesh Chandimal.
"If they get regular opportunities in Test match cricket, they will become a formidable team."