Pakistan survived an almighty scare before condemning Ireland to a five-wicket defeat in the hosts' maiden Test match on day five at Malahide.
Ireland seamers Tim Murtagh (2-55) and Boyd Rankin (1-57) reduced the tourists to 14-3 inside five overs as they began their chase of 160 under overcast skies in Dublin, after the home side had been dismissed for 339 earlier in the day, with Kevin O'Brien unable to add to his overnight 118.
However, debutant Imam-ul-Haq (74no), the nephew of Pakistan great and current chief selector Inzamam, hit his maiden Test fifty and shared a fourth-wicket stand of 126 with Babar Azam (59) to steer the visitors to their target before tea - Andrew Balbirnie left to rue dropping Babar on nine in the slip cordon with the score on 60.
Pakistan subsequently ended Ireland's hopes of becoming just the fourth side to win a Test having followed on, after England in 1894 and 1981 and India in 2001, with each of those victories coming against Australia.
Sarfraz Ahmed's men will now head to England for a two-Test series, with games at Lord's from May 24 and Headingley from June 1, while Ireland can reflect on genuinely threatening to win their inaugural Test, something only Australia, against England in Melbourne in 1877, have achieved.
O'Brien became the first Ireland player to score a Test century on day four to lift his side to 319-7 by stumps and a lead of 139, but perished to the first ball he faced on day five, snicking an out-swinger from Mohammad Abbas (5-66) behind to Haris Sohail at slip while on the drive.
Abbas wrapped up the innings, and his second five-for in Tests, when he bowled Rankin (6) and Tyrone Kane (14) off inside-edges - but it was then Ireland's pacemen who came to the fore.
Murtagh had Azhar Ali (2) caught at slip fourth ball and then bowled Asad Shafiq (1) through the gate midway through the fifth over, with his wickets sandwiching Rankin's dismissal of Sohail (7) - Sohail steering low to Ed Joyce at gully after Rankin came close to overstepping.
Imam and Babar endured nervy moments, too; Imam edging short of Paul Stirling at slip and Babar cue-ending a ball over his stumps prior to lunch, before Babar was shelled by Balbirnie after the interval.
Balbirnie, who had bagged a pair with the bat, finally had something to cheer when he ran out Babar from cover with 20 runs required, the outgoing batsman having secured his fifth Test fifty from 89 balls by slamming a Stuart Thompson no-ball to the fence.
However, Imam, who reached his half-century from 61 balls by clipping Kane for three, ushered Pakistan home with Shadab Khan (4no) after skipper Sarfraz (8) had fallen lbw to Thompson (1-31), Imam sealing victory by knocking Kane past square leg for two at the end of the 45th over.
Watch Pakistan's Test series in England live on Sky Sports Cricket, starting with the opener at Lord's from May 24. Ireland are back in action on Sky Sports on June 27 and June 29 when they play India in Twenty20 internationals at Malahide.