Chasing a Duckworth-Lewis revised target of 219 in 31 overs, Zimbabwe rode on Ervine's 55-ball unbeaten knock to win with 10 balls to spare at the Mahinda Rajapaksa International Stadium.
Earlier, openers Niroshan Dickwella (116) and Danushka Gunathilaka (87) put together 209 runs in Sri Lanka's 300-6 -- becoming the first pair in ODI history to score back-to-back double century partnerships.
Also Read: Sri Lanka vs Zimbabwe 4th ODI, As it Happened
The left-handed batting duo had put on a 229-run match-winning stand in the previous ODI on Thursday at the same venue but their efforts went in vain the second time around.
Solomon Mire (43) and Hamilton Masakadza (28) set up the Zimbabwe chase before teenage leg-spinner Wanindu Hasaranga, who took three wickets, got the openers trudging back to the pavilion.
But Ervine and Malcolm Waller (20) made sure the chase remained on track with their 43-run sixth-wicket partnership after rain interrupted play for over one-and-a-half-hours.
Ervine, a left-handed batsman and a right-arm spinner, smashed eight fours and a six to get the man of the match award.
For the hosts, Dickwella hit his second successive century with a commanding knock, while Gunathilaka was bowled 13 short of what could have been his second ODI ton.
Wicketkeeper-batsman Dickwella, who scored 102 on Thursday at the same venue, played a patient 118-ball knock laced with eight boundaries before being trapped lbw.
Zimbabwe off-spinner Waller got the two prized wickets in successive overs to pull things back for the visitors.
Paceman Chris Mpofu also got two wickets to rattle the Sri Lankan middle-order as the hosts slipped from 216-1 to 263-5.
Skipper Angelo Mathews then lifted the total with his 40-ball 42, with help from Wanindu Hasaranga (19 not out) during their 37-run partnership for the seventh wicket.
The fifth and deciding ODI is scheduled on Monday at the same venue. The two sides will also play a one-off Test starting July 14.
Angelo MathewsCraig ErvineDanushka GunathilakaHamilton MasakadzaLasith Malinganiroshan dickwellaSolomon MireSri Lanka vs ZimbabweWanindu Hasaranga+
First Published: July 8, 2017, 7:17 PM IST