By the close, O'Brien and Tyrone Kane, who had lasted just two balls in the first innings, had added another 23 runs and Ireland were dreaming, not just of becoming only the second team to draw their inaugural Test but actually being the first, since Australia in the first ever in 1877, of winning it.
Imam-ul-Haq's half-century steered Pakistan's fortunes as they sealed a five-wicket win over Test debutants Ireland.
With a performance to silence any who doubted if they deserved their place at cricket's top table, Ireland almost produced what would have been one of the sport's most unexpected results, coming back from the indignity of the follow on to push Pakistan all the way.
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.
Kevin O'Brien, who on Monday became the first Ireland batsman to score a Test hundred, fell to his first ball on Tuesday.
It seemed poetic that the first wicket of the Pakistan innings fell courtesy of Tim Murtagh, the leader of the Irish bowling attack, in the first over itself with Azhar Ali hopping around and succumbing to flawless line and length, Paul Stirling pouching a brilliant catch at first slip.
Their association could have come to an end much sooner than it did, but Andrew Balbirnie spilled a tough chance in the slips when Babar Azam had just 9 to his name.
74* - Imam-ul-Haq's unbeaten 74 is the 2nd highest individual score in a successful chase by a Pakistan player on Test debut.
Murtagh gave Ireland a flying start with the ball on the final day
Ireland started the day on their highly creditable overnight 64 without loss.
"We needed this kind of performance before playing England", Pakistan captain Sarfraz Ahmed said. Having been handed his Test debut at Dublin, the left-handed opener's first innings had been eventful but short-lived. The former England captain spoke to Mirror on the unique initiative, the upcoming India-England series, Virat Kohli's decision to play county cricket and 100-ball cricket. It was the first ball he faced.
"The biggest thing is the way we fought back in the second innings and that showed the character that we have".
It was yet another unforgettable memory for Kevin's parents, Brendan and Camilla, who were also in Bangalore on the night that their youngest son broke World Cup scoring records and English hearts in the 2011 World Cup.
Ireland players after Pakistan secured a five-wicket win.
"This Test match will have gone a long way to providing the next generation of cricketers, I'm sure".
But after a glorious four days in Malahide, following a washed-out opening day, there is now no question that the 11th team to play Test cricket are in any way out of place. Although it was nearly inevitable that the upset was too far gone, Ireland further added to a respectable scoreline and outstanding match in general producing a further outing through Stuart Thompson's dismissal of Safraz Ahmed for 8, Pakistan now at 152-5.