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, the debutant opener, and Babar Azam fashioned the significant partnership Pakistan needed to avert disaster after they had slipped to 14 for 3 chasing 160.
Imam has already dealt with the pressure of expectation - his uncle, Inzamam-ul-Haq, is one of Pakistan's greatest batsmen, as well as the chief selector - and he played an innings of calm authority to record his maiden half-century, characterised by composure and sound shot selection.
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.
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.
Pakistan eventually closed out the game, securing 160-5 to take the inaugural test match, with Imam finishing 72 not out to cap off a fine debut display for him.
"They have a quality line-up but if we had got another couple and break that partnership, then it's completely game on", added Porterfield, reflecting on the missed opportunity to cause another major shock in world cricket.
The Ireland and Pakistan players together at Malahide.
Babar, who was dropped on 9, was run out 20 runs short of the target.
Trump berates DHS Secretary Kirstjen Nielsen over border security
The New York Times and Politico reported that Nielsen, who began the job in December, drafted a resignation letter. They spoke on condition of anonymity because they were not authorized to disclose private conversations.
The now 26-year-old Amir's cricket career nearly came to an end following his involvement in a spot-fixing scandal during a 2010 Test against England at Lord's.
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 in the grounds of Malahide Castle, just north of Dublin.
With Pakistan requiring 160 to win, Ireland sensed the possibility of a sensational victory, quickly reducing their opponents to 14/3.
Now Sarfraz Ahmed, if only for a few hours perhaps, has to contemplate whether he made a wise move by becoming the first Pakistan captain to enforce a Test follow-on in 16 years. That's always been known to be there but Test cricket is Test cricket for a reason, it's there in the name, you did get tested and we were after the first innings.
Murtagh gave Ireland a flying start with the ball on the final day.
O'Brien was just the fourth player to reach three figures in his country's first men's Test, with Australia's Charles Bannerman, Zimbabwe's Dave Houghton and Bangladesh's Animul Islam the others.
Ireland also had a chance to become the third team, after England and India, to win a Test after following on.
- Tesla bursts into flames after fatal crash in Switzerland
- Trivia Tuesday: NBA Lottery picks from non-power schools
- Manchester City's record breaking season by the numbers
- Slain trooper to be honored at Peace Officers Memorial
- USA and China still "very far apart" on trade, says U.S. ambassador
- Pompeo: US to lift sanctions if North Korea dismantles nuclear weapons program
- Microsoft Surface Hub 2 may actually make videoconferencing cool
- Yates soars into Giro lead, Chaves wins stage
- Rage 2 Gameplay Trailer is here, The Wasteland is One Crazy Drug!
- 70 officers and deputies escort fallen cop's son back to school