The 21-year-old was unbeaten on 169 -- 52 runs more than his team managed in the first innings -- when rain forced the players off the ground 10 overs after tea with Sri Lanka on 282-6.
Dilruwan Perera was on five with Sri Lanka leading by 196 runs with four wickets in hand as rain continued to plague the Test which has already seen the final sessions of the first two days washed out.
Resuming on six for one, Sri Lanka lost Dimuth Karunaratne to Mitchell Starc in the third delivery of the day.
Mendis then forged two important partnerships to rebuild the Sri Lankan innings, raising 117 runs -- comfortably the highest of the match so far -- with Dinesh Chandimal (42) and 71 with Dhananjaya de Silva (36) to haul his team back into the contest.
In a match where no other batsman has managed a fifty, Mendis brought up his maiden hundred in style, slog-sweeping Lyon over midwicket for six.
With Mendis on song, Sri Lanka completely dominated the post-lunch session, adding 137 runs at a four-plus run rate for the loss of Chandimal's wicket.
Mendis hit 20 boundaries, including a couple of glorious cover drives, in his 243-ball masterclass and had contributed nearly 60 percent of the team score in the second innings.
The visitors' woes were compounded when spinner O'Keefe hobbled off the ground, Cricket Australia later confirming in a tweet that he has a "right hamstring issue".