Chasing 289, Pakistan lost Saim Ayub for 33 and Fakhar Zaman for a solid 78, but Babar controlled the innings with trademark calmness.
Babar hit his first international century in more than two years as he struck 102* off 119 balls, anchoring the chase and pacing it perfectly.
Mohammad Rizwan provided strong support with an unbeaten 51, as the pair added 112 runs for the third wicket to seal the win with 10 balls left.
Earlier, Sri Lanka posted 288/8, with Janith Liyanage (54), Kamindu Mendis (44), and Wanindu Hasaranga (37*) contributing in the middle and lower order.
Haris Rauf and Abrar Ahmed took three wickets each, keeping Pakistan in the contest despite Sri Lanka’s late acceleration.