The tourists were precariously placed at 83 for three, with skipper Steve Smith unbeaten on 26, when bad light forced an early end to play for the fourth day running in Pallekele.
The world number one Test team still need another 185 runs for victory on the final day tomorrow, when Sri Lanka's trio of spinners will expect to capitalise on their early inroads against the tourists.
Usman Khawaja started positively with three fours but he was ruled leg before wicket to off-spinner Dilruwan Perera when he attempted a sweep shot after making 18, leaving Australia reeling at 33/2.
Then the debutant Lakshan Sandakan joined the party with a ball that turned sharply and bowled opener Joe Burns who had looked well set on 29.
More From This Section
One run later, first innings top scorer Adam Voges was ruled lbw to Perera for no score, but the batsman reviewed the decision successfully.
Smith's 54-ball innings has not featured any boundaries so far, while his partner Voges was batting in a similarly steadfast mood, reaching nine at the close of play off 25 deliveries.
Australia's struggles against the Sri Lankan bowlers further underlined the importance of Kusal Mendis' superb maiden Test century in what has been a low-scoring Test. No other player on either side has passed 50.
After starting the day unbeaten on 169, Mendis only managed another seven runs before he played away from his body to a full length delivery from Mitchell Starc to be caught behind by wicketkeeper Peter Nevill.
Herath and Nuwan Pradeep added 30 runs for the last wicket off 29 deliveries before the Sri Lanka innings ended after substitute fielder Moises Henriques took a spectacular catch at extra cover.
Sri Lanka, who were 282 for six overnight, eventually managed to reach a total of 353, 267 runs ahead of the Australians.
It was a remarkable turnaround after they conceded a first innings lead of 86 to the tourists who were presented with the mace as the world's number one team on the eve of the match.
The second Test will be held in Galle from August 4-8 and the third in Colombo from August 13-17.