Left-arm quick Mohammad Aamer was five not out and Umar Gul, who hit the winning run off Mitchell Johnson, was one not out as Pakistan ended a run of 13 straight Test defeats by Australia – a record for one country against another.
Australia paid the price for a first innings batting collapse that saw them bowled out for just 88 – their lowest Test total since they were dismissed for 76 by the West Indies in 1984.
Pakistan made 258 in response after Australian bowler Shane Watson took a Test best six for 33 to limit the damage done in the first innings.
Australia were bowled out for 349 in the second innings as captain Ricky Ponting hit 66 to become one of two batsman in history to score 12,000 Test runs, but it was not enough, with Pakistan reaching their target with a full day and three wickets to spare.
Pakistan now have a short turnaround before a four-Test series against England starts at Trent Bridge on July 29.
Australia would play two Tests against India in October before attempting to regain the Ashes from England on home soil, in a five-Test campaign that starts in November.