At the close of play on the third day here, Sri Lanka had reached 282 for six, with Mendis unbeaten on 169, as the hosts gained the upper hand in a gripping contest against the world's number one Test team.
Mendis' knock was the highest score by any Sri Lankan against Australia at home and came after no player from either side had managed to even score a half century in the first innings.
He played Australia's seamers with confidence before cutting loose against the spin bowlers with an array of boundaries.
He reached his century in spectacular fashion when he slog-swept Nathan Lyon for six and then reached his 150 by cutting the same bowler for four.
Also Read
wicket partnership.
After Chandimal was out lbw for 42 off Marsh's bowling, the debutant de Silva then scored 36 in a partnership worth 71 before becoming Lyon's 200th Test victim, caught at long-on by Usman Khawaja.
Sri Lanka only managed another eight runs before bad light and then rain brought an early end to proceedings for the third afternoon in a row but they now have an unlikely sniff of victory.
Starting the day on 6 for 1, still 80 runs behind the Australians, the hosts were soon in even deeper trouble when Karunaratne was judged lbw against Mitchell Starc without adding to the overnight score.
A total of 75 overs so far have been lost due to rain and bad light but the steady succession of wickets on the first two days means that the match is still expected to yield a result.
Adam Voges top-scored in Australia's first innings total of 203 all out in reply to Sri Lanka's score of 117.
The match is the first in a three-Test series which will also see the Australians travel to Galle and then Colombo.