Shah ended opener Usman Khawaja's fighting innings at 141 and then removed Mitchell Starc and Peter Siddle in quick succession to reduce Australia to 333-8, keeping Pakistan´s victory hopes alive till the last over of the final day.
Khawaja, who hit 11 boundaries, had a top score of 26 in five previous Tests in Asia.
The captain Tim Paine (61) and Nathan Lyon (5) held firm in the final session as Australia finished on 362 for eight to seal the draw.
Pakistan scored 482 and 181-6 declared.
Khawaja and Paine seemed to be carrying Australia to safety in their sixth-wicket stand lasting 36 overs.
Michael to make landfall in Florida as major hurricane: NHC
Nathan Deal on Tuesday issued a state of emergency covering 92 counties - almost the entire lower two-thirds of his state. Anxious meteorologists said it had the potential to become one of the worst storms in the history of Florida's Panhandle.
He was on 44 when Shah's lbw appeal was turned down and Sarfraz Ahmed did not review even though replays suggested the leg-spinner had trapped the batsman plumb in front.
Jon Holland, who took the key wicket of Azhar Ali for four on Tuesday, dismissed opener Imam-ul-Haq for 48, caught and bowled off a flighted delivery.
Pakistan were only rewarded after lunch when they took the second new ball as soon as it was due and Hafeez trapped Head leg-before with the first ball.
Australia's hero was Khawaja, who started the day on 50 not out as Australia resumed on 136-3.
But Paine and Lyon batted resolutely against Shah (4-114), seamer Mohammad Abbas (3-56), and offspinner Bilal Asif, who took six wickets in the first innings but none in the second.
At stumps, opener Usman Khawaja was batting on a fighting 50 and Travis Head on 34, as the pair had added an invaluable 49 for the unbroken fourth-wicket stand to prolong the visitors' resistance on a tired and spinning pitch. Khawaja departed an hour into the last session, but he'd given his teammates a blueprint on how to defend.