One-drop batsman Babar knocked a fighting 133-ball 103 while Shadab scored a career best 52 not out to lift Pakistan from a struggling 79-5.
That was before Shadab the bowler returned with his best figures of 3-47 to dismiss Sri Lanka for 187 all out in 48 overs.
The 23-year-old Babar and Shadab, who turned 19 earlier this month, were engaged in a match-turning 109-run seventh wicket stand which helped Pakistan reach 291-9 on a sluggish Sheikh Zayed Stadium.
The victory gives Pakistan a 2-0 lead in the five-match series while this becomes Sri Lanka's ninth defeat in a row.
Skipper Upul Tharanga became the first Sri Lankan and 11th batsmen in the one-day history to carry his bat through a complete innings with a fighting 144-ball 112 not out with 14 boundaries -- his 15th ODI century.
It were bowlers who helped Pakistan defend a low total despite Tharanga and Jeffrey Vandarsay (22) put up a fighting 76-run eighth wicket stand, but it wasn't enough.
Dropped twice on 13 and then on 20, Tharana stood alone as Sri Lanka needed 51 off the last five overs but the last two batsmen were run out and he was left stranded.
It were bowlers who helped Pakistan defend a low target.
Once paceman Junaid Khan removed Niroshan Dickwella for three in the third over, spinners Shadab, Shoaib Malik (1-17) and Mohammad Hafeez (1-24) rocked the Sri Lankan batting with regular wickets.
Pakistan skipper Sarfraz Ahmed praised his bowlers.
"I can't praise the bowlers enough for defending this 220," said Ahmed. "Babar and Shadab are very young and it was nice to see them bat so well."
Tharanga admitted his batting let the team down.
"It's disappointing to lose," said Tharanga. "When you're 90 for 7, it's a tough task. It was good to carry the bat, but I'm disappointed with the result."
Earlier, Azam followed up his 103 which anchored Pakistan's 83-run win in the first game in Dubai on Friday, once again anchoring the innings.
Pakistan, who won the toss and batted, found the going tough as they lost half the side at the end of 20 overs for just 79, but Azam and Shadab led the fightback.
Azam brought up his seventh one-day hundred off 130 balls -- his fourth this year -- with a sharp double in the 49th over.
Shadab, who scored 14 not out in his only previous innings, played a support role during which he hit just one boundary off 68 balls.
Sri Lankan new-ball bowlers Lahiru Gamage (4-57) and Suranga Lakmal (1-42) made early inroads with three wickets inside first power-play of ten overs.
Gamage had Fakhar Zaman dismissed for 11 and Mohammad Hafeez for eight while Lakmal dismissed out-of-form Ahmed Shehzad for eight.
Medium pacer Thisara Perera (2-34) then struck twice, removing Shoaib Malik (11) and Sarfraz Ahmed (five) to leave Pakistan in a spot of bother.
Azam added 22 for the sixth wicket with Imad Wasim (ten) before his stand with Shadab gave Pakistan's total some respectability.
The remaining matches will be played in Abu Dhabi (October 18) and Sharjah (October 20 and 23). The two teams will also play three Twenty20 internationals, the first two in Abu Dhabi (October 26 and 27) and the last in Lahore (October 29).
Babar AzamJunaid Khanniroshan dickwellaPak vs SLPakistan vs Sri Lanka 2017Shadab Khanshoaib malikupul tharanga
First Published: October 17, 2017, 8:40 AM IST