Bairstow's unbeaten 108 off 48 balls, with eight fours and nine sixes, see Punjab secure the win with eight balls to spare
Sri Lanka's spin spearhead Rangana Herath struck early as Zimbabwe were reduced to 38-3 after winning the toss and electing to bat first.
But left-handed Ervine, who hit his second Test hundred, compiled two half-century partnerships with Sikandar Raza (36) and Malcolm Waller (36) to lead the fightback for Zimbabwe, who beat Sri Lanka 3-2 in the recent one-day international series.
Left-arm spinner Herath finished as the most successful bowler with four wickets for 106 Sri Lanka, who were playing the first match under new Test captain Dinesh Chandimal.