The hosts, who resumed their second innings at 63-1 chasing an improbable target of 550, were shot out for 221 in the post-lunch session of the fourth day at the Sher-e-Bangla stadium.
Shah, who took three for 58 in the first innings, once again baffled the Bangladesh batsmen with his leg-spin and googly on the wearing pitch to grab four for 73 in the second knock.
Mominul Haque played a lone hand for the hosts with 68, joining West Indies great Vivian Richards and the Indian duo of Virender Sehwag and Gautam Gambhir as the only batsmen to score 50 runs or more in 11 consecutive Tests.
Shuvagata Hom hit 39, sharing a ninth-wicket stand of 44 with Mohammad Shahid, to steer Bangladesh past the 200-run mark after they were reduced to 143-7 soon after lunch.
The match ended at the fall of the ninth wicket as Shahadat Hossain was unable to bat after suffering a serious knee injury on the first day.
The win helped Pakistan end an otherwise dismal month-long tour on a positive note after being routed 3-0 in the one-day series and losing to Bangladesh for the first time in a Twenty20 international.
It was Bangladesh's ninth loss to Pakistan in 10 Tests, the only consolation coming through a draw in the first Test of the short series in Khulna last week.
"This was a much-needed win for us," Pakistan captain Misbah-ul Haq said. "The team showed great character after what happened in the earlier games.
"The key was the way Younis Khan and Azhar Ali batted in the first innings to put up a 250-run stand. There was also more bounce in this wicket than in Khulna which our bowlers enjoyed.
"But Bangladesh must be congratulated (for) the way they played on this tour. The draw in the first Test was like a victory for them. I wish them well for the future."
Bangladesh captain Mushfiqur Rahim said he was very disappointed at the defeat after losing a frontline bowler in Shahadat on the first morning.
"Nothing went right for us from the first day," he said. "I don't think we executed our plans well and that is why we lost the game."
Rahim said his team would however take a lot of positives into next month's one-off Test at home against India which will be followed by three one-day internationals.
"Tamim Iqbal and Imrul Kayes had a good series and Mominul scores well consistently. But the bowlers need to be aggressive to keep us in the game for five days.
"They must realise that to compete and win Test matches, 20 wickets need to be taken. We will look to do that against India."
Pakistan turned the screws on the hosts with four quick wickets in the morning session to leave the rivals tottering at 126 for five.
Seamer Imran Khan, a late replacement for the injured Rahat Ali, dealt two major blows when he removed the in-form Tamim and Mohammad Mahmudullah in the space of nine runs.
Tamim, who slammed a double-century in the first Test, was caught behind by wicket-keeper Sarfraz Ahmed for 42 as he slashed at a short delivery from Imran.
Mahmudullah made two when he edged Imran to second slip where Younis Khan picked up the catch on second attempt as Bangladesh slipped from 86-1 to 95-3.
Off-spinner Mohammad Hafeez struck in his first over when Shakib Al Hasan (13) stepped out to loft a flighted ball and gave Wahab Riaz an easy catch at mid-off.
COMMENTS (5)
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ