West Indies had defied Pakistan's bowlers well until the 44th over with the score 106 for 2, but they then lost Marlon Samuels (30) and Kraigg Brathwaite (21) in the space of three balls without adding any further runs.
Nightwatchman Devendra Bishoo and Jermaine Blackwood were yet to score as West Indies trail Pakistan's first innings total of 452 by 346 runs with six wickets intact.
Darren Bravo, who made 87 and 116 in the first Test in Dubai, made an attractive 43 but his dismissal left Pakistan in a dominant position.
Bravo, who opened the innings after Brathwaite was off the field when Pakistan were batting and could not come in at the start, helped the tourists reach 27 without loss at the tea interval.
More From This Section
But in the third over after tea Rahat gave Pakistan the breakthrough when he trapped Leon Johnson leg-before for 12.
Bravo and Brathwaite took the score to 65 before drama unfolded involving English umpire Michael Gough as two of his decisions were overturned on referral.
Misbah reviewed the decision and television replays showed Bravo was leg-before for 43.
The very next ball Shah trapped Samuels in front of his stumps and Gough raised his finger, only for a review to grant the batsman a reprieve as replays showed he had hit the ball.
Earlier, Pakistan skipper Misbah missed out on his 11th Test century by just four runs, but Sarfraz Ahmed (56) and Mohammad Nawaz (25) added 70 for the seventh wicket to ensure Pakistan crossed the 450-mark.
Sohail Khan hit five boundaries before he became one of
three victims for Jason Holder, who finished with 3-47.
Pakistan had resumed the day on 304-4 in the hope that Misbah and nightwatchman Shah would survive the second new ball which the West Indies took at the start of play.
Shah was fortunate to escape a leg-before review off Holder but Misbah was not so lucky as he was dismissed in the next over.
Misbah missed an inswinging delivery which hit him in front of the stumps, with umpire Gough raising his finger. The Pakistani skipper reluctantly reviewed the decision but without success.
Ahmed paced his innings well, hitting six boundaries in his 59-ball knock, taking Pakistan past the 400 mark.
Pakistan lead the three-match series 1-0 after winning the first Test -- a day-night affair played with a pink ball -- by 56 runs.