Ireland's bid for an unlikely victory in its inaugural Test came up short as debutant Imamul Haq steered Pakistan out of trouble and to a five-wicket win on the final day on Tuesday.
Chasing 160 to win, Pakistan slumped to 14-3 and looked in real danger of becoming just the fourth team to lose a Test after enforcing the follow-on.
Imam showed his maturity and class to guide the tourists away from danger, scoring the winning runs to finish on 74 not out as Pakistan reached 160-5 just before tea.
It justified his call-up by Pakistan's chief selector, his uncle and former Test captain Inzamamul Haq.
Imam shared a vital 126-run stand with Babar Azam (59) for the fourth wicket.
The Irish can be proud of taking Pakistan all the way in their first match in cricket's longest format after being awarded Test status last June, especially having been bundled out for 130 in their first innings.
Resuming on Tuesday on 319-7 in their second innings after being asked to follow on, they added only 20 runs to their total but still left a challenging target for a Pakistan team that has a recent history of stumbling in small run chases.
And when Pakistan lost three wickets two to paceman Tim Murtagh in the opening 27 balls of the reply, Ireland had a strong chance of becoming the first team to win its maiden test after Australia against England in 1877 in cricket's first Test.
Imam held his nerve, hitting eight fours in a 121-ball knock.
Babar, who was dropped on 9, was run out 20 runs short of the target.
Earlier, Mohammad Abbas, benefiting from plenty of swing movement in overcast conditions, took the final three wickets of Ireland's second innings, including century-maker Kevin O'Brien.
Resuming on 118, O'Brien slashed at the first ball he faced on Tuesday a wide one from Abbas and edged to first slip.
Abbas also took the wickets of Boyd Rankin (6) and Tyrone Kane (14), who were both bowled, to finish with figures of 5-66. He had nine wickets for the match.
Pakistan now heads to England for a two-test series, starting next week at Lord's.
Ireland doesn't play another test this summer as it eases into life in the longer format. India visits for two Twenty20s next month.
Only three teams have won a test after following on England in 1894 and 1981, and India in 2001. Australia was the opponent on each occasion.