Amir's three wickets earlier in the day had put Pakistan into a position from which an innings win seemed entirely possible - even likely - but O'Brien and Stuart Thompson combined for a 114-run rearguard that not only pushed Ireland in front and burnished local pride, but allowed them to sleep on the possibility of another famous upset.
Imam-ul-Haq (74 not out) and Babar Azam (59) then combined to dash dreams that Ireland, the 11th nation to play men's Test cricket, would record a remarkable win.
A magnificent rearguard hundred from Kevin O'Brien gave Ireland a lead of 139 in their maiden Test and the prospect of giving Pakistan an awkward run chase.
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.
In the end, Ireland were beaten in their maiden Test, suffering the same fate as eight of the other ten members of cricket's most exclusive club.
Ireland's Test cricket debut falls short as nervy Pakistan claim victory
"How we went about that to get up close to 350 just showed what we've got in the changing rooms and the passion that we've got". Murtagh stepped up with two wickets to his name, Azhar Alin was out for 2 off the fourth ball, leaving the game well and truly on.
Babar was dropped on nine runs in the 19th over when Balbirnie could not hold a catchable chance and the right-hander immediately made Ireland pay by thumping two of his next four deliveries through the covers for boundaries.
The partnership built between the two shows great signs for Pakistan's upcoming test against England in Lords, most notably Imam's outstanding batting performance.
Pakistan bowling coach Azhar Mahmood suggested after stumps on Sunday that Amir's lengthy time away from the game allied to the fact he had been involved in all three global formats-Tests, one-dayers and Twenty20s-since coming back had taken a toll on the swing bowler.
"I think it was a fantastic team effort, yesterday belonged to Kevin and very well supported by Tommo and TK". That was as good as it got for Ireland.
Ireland can be extremely proud and their display gave a basis to compete on equal terms and they certainly do not look like the new boys of Test cricket. It was our first Test match and it was tough on the first day, we struggled a bit with the emotions.
And only three teams - one for every century in which Test cricket has been played - have won after following-on, with South Africa in 1894, England in 1981 and India at Kolkata in 2001, all beating Australia having been sent back into bat.More news: The US called the conditions for complete nuclear disarmament of the DPRK
More news: Whatsapp Introduces New Features to Group Chats - Permissions, Private Messages and Descriptions
More news: Ronda Rousey Challenged By WWE Champion For Title Match