Set a target of 202, the visitors reached 109-0 at stumps and need only 93 runs on the final day on Tuesday.
Ali was batting on 56 at the end of the day's play, adding to his first-innings score of 133, while debutant Shafique was unbeaten on 53.
Fast bowler Shaheen Afridi earlier claimed 5-32 to help Pakistan bowl out Bangladesh for 157 runs in their second innings despite wicketkeeper-batsman Liton Das making a fighting fifty.
Resuming on 39-4, Bangladesh looked down and out once they lost Mushfiqur Rahim in the first over of the day, before Liton, who struck a hundred in the first innings, hauled the hosts back to respectability with 59 off 89 balls.
Afridi trapped Liton leg-before and then had Abu Jayed out for a duck to complete his fourth five-wicket Test haul.
Off-spinner Sajid Khan, who finished with 3-33, wrapped things up by dispatching Taijul Islam.
The hosts had got off to a positive start with Mushfiqur hitting a boundary off the first ball of the morning, bowled by Hasan Ali.
But two balls later he left a wrong delivery and departed for 16 after Hasan struck off-stump.
Liton joined overnight batsman Yasir Ali to prevent further collapse.
Just when they looked ready to prosper, Afridi's low bounce hit the helmet of Yasir, who retired hurt after making 36.
Liton survived on 26 when he was given out, caught at short leg off Sajid Khan.
The replay showed that the ball only hit his pad and was going down the leg.
Sajid was rewarded for his persistence as he trapped Mehidy Hasan leg-before for 11.
Substitute Nurul Hasan replaced Yasir after Mehidy's dismissal and barely survived a strong caught-behind appeal just before lunch.
Nurul heaved one at long-on to Faheem Ashraf off Sajid after the break, getting dismissed for 15, and Pakistan took little time to take the remaining wickets.
Bangladesh have failed to defeat Pakistan in any of their 10 previous encounters.
from latest-news - SUCH TV https://ift.tt/3E6s0tw
via IFTTT