Seeking to avoid a series whitewash after losing the first two matches, Pakistan appeared to be heading for a big total when they reached a comfortable 203 for two in the 39th over.
But Azhar's dismissal at that stage for a fluent 101 off 112 balls sparked a dramatic collapse in which the tourists lost their last eight wickets for just 47 runs at Dhaka's Sher-e-Bangla stadium.
Shakib Al Hasan, Mashrafe Mortaza, Arafat Sunny and Rubel Hossain claimed two wickets each as Bangladesh clawed their way back after wayward bowling earlier in the innings.
Azhar led from the front to become the first Pakistani captain in five years to score an one-day century following Shahid Afridi's 124 against Bangladesh in 2010.
Having won the toss and elected to bat, Azhar shared an opening stand of 91 with debutant Sami Aslam, who made 45.
Nasir Hossain provided the breakthrough when he had the left-handed Aslam caught by wicket-keeper Mushfiqur Rahim.
Senior all-rounder Mohammad Hafeez was bowled by Sunny for four to extend his batting misery in a series in which he compiled just eight runs in three matches.
Haris Sohail (52) added 98 with Azhar for the third wicket before the rot set in.
Azhar was bowled by Shakib and Mashrafe dismissed Haris as Bangladesh began their comeback.
Pakistan dropped off-spinner Saeed Ajmal, Sarfraz and injured paceman Rahat Ali to play Umar Gul, Zulfiqar Babar and the uncapped Sami. Bangladesh retained the same side from the previous game.
The two teams will play a Twenty20 international on Friday before starting a two-Test series from April 28. – AFP
Original source: Captain Ali shines for Pakistan