The 33-year-old Azhar, a veteran of 65 Tests, made 125 off 188 balls, including 13 fours and two sixes, before he was last man out in a Somerset total of 362 for nine declared at New Road.
England off-spinner Mooen Ali did his chances of a Test recall ahead of next week's series opener against India at Edgbaston no harm with a return of five wickets for 107 runs.
Worcestershire then lost Daryl Mitchell (six) and Moeen (seven) before ending the third and penultimate day on 50 for two, leaving them needing a further 393 runs to win on Wednesday.
"I'm really happy. It is my first game for Somerset and I've been made welcome," Azhar told the county's website.
"I really enjoyed batting out there and it was really pleasing to get some runs in the first game and hopefully I can build on that."
Reflecting on his innings, Azhar, who played in Pakistan's drawn Test series in England earlier this season, added: "Moeen started to turn the ball out of the rough so I thought attacking him early on was the right option because if you are bogged down, they can bring a short leg into play so, I had to go after him to start with."
"We wanted to score runs as well to be in a position to boss the game. That is why I played positively and it paid off," explained Azhar, who was eventually caught off a reverse-sweep against Moeen.
Somerset have had a superb return from their overseas batsmen so far this season after deciding not to go ahead with bringing Cameron Bancroft to Taunton following the Australian's role in a ball-tampering scandal in South Africa earlier this year.
They signed Matt Renshaw, a fellow Australia batsman, in his place and he went on to make three hundreds, while averaging 51.30, before breaking a finger against Surrey last month -- an injury that paved the way for Azhar's arrival.
First Published: July 25, 2018, 8:48 AM IST