Pakistan kept their one-day series against Australia alive thanks to centuries from captain Babar Azam and Imam-ul-Haq.
Ben McDermott scored a knock of 104 from 108 balls as Australia finished on 348 for eight to set the hosts a huge target to level the three-match series.
However, Pakistan responded and delivered a sensational performance with the bat as Imam hit 106 from 97 balls while Azam smashed 114 from just 83 deliveries.
Khushdil Shah then scored an unbeaten 27 from 17 deliveries as Pakistan went on to win with an over to spare. It was the country's highest successful chase in a one-day international.
The first crucial partnership saw Imam put on 118 for the first wicket with Fakar Zaman (67). He then put on another 111 for the second with Azam.
The foundations for Australia's total were based on McDermott's stand of 162 for the second wicket with Travis Head (89). Marnus Labuschagne (59) and Marcus Stoinis (49) also made important contributions.
The 349-run chase by Pakistan was the tenth-highest successful run chase in ODI cricket. The series is now level at 1-1 with the third match also in Lahore on Saturday.