Mohammad Amir gave Pakistan a boost ahead of their series with England by taking two wickets in quick succession as he returned to the fray against Ireland on Monday despite a troublesome knee injury.
Kevin O'Brien failed to add any runs to his overnight score of 118 before swinging at a wide delivery from Mohammad Abbas and edging to first slip.
34y 68d - Kevin O'Brien became the 3rd oldest player in the Test history to score a century on debut.
That win, coupled with another big upset by the Irish against Pakistan in Kingston, Jamaica at the previous World Cup - where O'Brien was there at the finish alongside Trent Johnston - kickstarted the push for Ireland to get Test status.
Soon, the home fans at Malahide were celebrating as Ireland's pacers tore through Pakistan's top-order.
Abbas swiftly removed Boyd Rankin (6) and Tyrone Kane (14) to return second-innings figures of 5-66.
"Three or four balls stayed quite low and went under Kevin's bat in the last over so hopefully it does get a bit up and down tomorrow", said Thompson, who himself returned a three-for in the first innings.
But at lunch Pakistan were 52 for three, still needing a further 108 runs to win, with left-handed opener Imam - the nephew of selection chief and former Pakistan batsman Inzamam-ul-Haq - 33 not out and Babar Azam nine not out.
The unanimous verdict from the cricket world showed that it was great to see Ireland play Test cricket, and even greater to come out with an extremely competitive performance on their Test debut. Stuart Thompson has already scored two centuries this season for club and province and he was quickly into his stride, a four through mid-wicket the best of the bunch before the tea interval.
Ireland's players react as Pakistan's Asda Shafiq loses his wicket.
What were your highlights from Ireland's first ever Test match?
However, with Ireland struggling at 157/6, Kevin O'Brien and Thompson came to the rescue as they amassed a 114-run partnership, during which Thompson brought up his half-century.
To Ireland's credit, they took the match to the fifth day and it looked as if they were in for a possible shock result before Pakistan took control of the match to take the win.
'We were definitely anxious at 14 for three, but we were confident we had a good batting side, ' said Pakistan captain Sarfraz Ahmed.
Pakistan's fielding became increasingly sloppy but shortly before the close O'Brien, on 118, nearly played on to Amir.