Gunaratne scored 116 to marshal the tail to good effect and frustrate the Zimbabwean bowlers
Playing just his second Test, Gunaratne scored 116 to marshal the tail to good effect and frustrate the Zimbabwean bowlers, before his dismissal brought the end of the Sri Lankan innings on the stroke of tea.
When Rangana Herath opened the bowling and grabbed the wickets of Tino Mawoyo and Hamilton Masakadza to reduce Zimbabwe to 17 for two, the hosts looked to be embarking on one of their trademark batting collapses.
But Chari and Ervine added 109 for the third wicket without being parted, taking Zimbabwe to stumps on 126-2 with both batsmen ending the day on 60 not out.
"We would have liked to have a few more wickets down but hopefully we can grab a few early on tomorrow," said Sri Lanka coach Graham Ford.
"We've seen Rangana turn some deliveries this evening, so once he gets a few going he becomes more of a factor."
The tourists began the day on 290-5, with Gunaratne on 13, and despite losing centurion Dhananjaya de Silva they were able to make rapid progress during the morning session.
De Silva was caught and bowled by leg-spinner Graeme Cremer for 127, before Gunaratne added 54 for the seventh wicket with Dilruwan Perera at a swift rate.
Perera was then trapped lbw by Cremer for 34, but Gunaratne went to lunch on 64 having helped Sri Lanka add 124 runs in the session.
After lunch the 30-year-old increased his rate of scoring further in a 75-run stand for the eighth wicket with captain Herath, who made 27.
Seamer Donald Tiripano had Herath caught behind and then bowled Suranga Lakmal, but last man Lahiru Kumara held on long enough for Gunaratne to reach three figures and carry the score past 500.
It was the fifth straight Test match in which Zimbabwe, who trail 1-0 in the two-match series, had conceded 500 runs in an innings.
Under pressure after two failures in the first Test, Chari not only put up stern resistance, but also took the attack to Sri Lanka.
The right-hander became the first Zimbabwean Test player to hit his first ball for six as he lofted Herath over long-on -- then repeated the stroke to go to his maiden Test fifty.
While Chari had two lbw decisions overturned on review, Ervine was generally untroubled as he stroked eight boundaries and the partnership rattled along at 3.7 runs per over.
"It was an individual plan to be more positive in the way that we got ourselves in," said Ervine.
"We need to turn up for that first hour tomorrow, and then the first session, and try and get through without losing a wicket."