Kevin O'Brien became the first Irishman to hit a half-century for his country as Ireland went in for tea on 212 for six in their second innings with a slender lead of 32 runs over Pakistan in their maiden Test outing in Malahide.
O'Brien, playing with confidence and control, took hold of an Ireland innings that was still in shaky water and steered them past their opponents' first innings total by breaking the 50 mark, ensuring the visitors will have to bat again if they wish to win this match.
Pakistan bowler Mohammad Amir was the star man in the day's opening session for the visitors, bowling with real venom and taking two quick wickets as Ireland tried to settle into a rhythm and get their batting attack looking dangerous.
There were doubts over Amir's fitness early in the day, but their star bowler was fit enough to take to the field against Ireland on the fourth day of their Test, with the tourists hoping he could bowl on Monday morning.
Amir came off late in the final session on Sunday when a chronic knee injury flared up, and he was not one of the first three bowlers used the following day as Faheem Ashraf, Mohammad Abbas and Rahat Ali took the ball instead.
Pakistan's first Test against England begins in 10 days at Lord's and they will hope Amir's issue does not prevent him from bowling in that.
Ireland resumed the penultimate day at Malahide on 64 without loss in their second innings, still 116 behind Pakistan's first-innings total, but they lost Ed Joyce with just five more on the board when he was run out on 43 by Ashraf's direct-hit.
In the over after Joyce departed, Ireland's number three Andrew Balbirnie suffered a pair, again falling lbw to Abbas, with the hosts' top order in danger of swiftly collapsing once more.
Both Niall O'Brien and William Porterfield should have been run out before Pakistan captain Sarfraz Ahmed finally turned to Amir, who bowled beautifully in beating Porterfield's outside edge on multiple occasions.
It looked as if that Irish duo would see Amir's spell off but he rallied with a full delivery that uprooted O'Brien's off and middle stumps - and nearly took leg out too - before Porterfield edged behind to Sarfraz off the same bowler.
That left Ireland 95 for four, still 85 behind, as lunch approached but, mercifully for the hosts, Amir was eventually taken out of the attack and temporarily left the field as Paul Stirling and Kevin O'Brien tried to dwindle down their side's deficit.
At lunch the hosts were 123 for four, still needing 57 more to reach Pakistan's first-innings total.
Abbas had another lbw appeal go in his favour to send back Stirling after lunch but Kevin O'Brien and Gary Wilson continued to bring the hosts closer to ensuring Pakistan would have to bat again.
However, that partnership was broken up, predictably by Amir, who came back into the attack and claimed his 100th Test wicket when Wilson went fishing outside off and edged to first slip.
With four wickets in hand, Ireland needed just 20 more to avoid an innings loss.
Amir nearly found Stuart Thompson's edge too with the very next ball but the Irish number eight quickly settled and he and Kevin O'Brien took 14 runs in two overs from Pakistan's chief threat.
That brought the hosts within touching distance of erasing Pakistan's lead and they moved ahead in the contest for the first time courtesy of Kevin O'Brien's edged four past the vacant second-slip region.
That took Ireland's most experienced cricketer onto 48 and he became their first male half-centurion in the Test format with a single down the ground before the second break of the day.