Kevin O'Brien scored Ireland's first Test century to bolster hopes of at least avoiding defeat in their debut in the five-day game against Pakistan.
Ireland resumed day four on 64-0 in their second innings having been forced to follow-on by the visitors, who reduced the hosts to 157-6 to seemingly put them in position for an emphatic victory.
Mohammad Amir, having been troubled by a knee injury on day three, looked back to fitness and form on Monday and did much of the damage with figures of 3-57.
But Amir and the rest of the Pakistan attack were frustrated by the brilliance of O'Brien, who forged a pivotal partnership of 114 with Stuart Thompson (53) and an unbroken one of 48 with Tyrone Kane (8), staying unbeaten on 118 to guide Ireland to 319-7 at the close on an historic day at Malahide.
Ireland therefore lead by 139 going into the final day, with a draw and even a victory still within their grasp after being applauded off the field by Pakistan at stumps following O'Brien's magnificent effort.
Opener Ed Joyce (43) was run out by Faheem Ashraf before Andy Balbirnie went for a duck five balls later as Ireland made a dreadful start to the day.
The prospect of defeat loomed ever larger after Amir dismissed any doubts over his ability to produce pace by sending Niall O'Brien's (18) off and middle stumps careering out of the ground, before then claiming the scalp of captain William Porterfield (32).
O'Brien's arrival at the crease prompted the first signs of Ireland resistance but wickets continued to tumble around him until Thompson joined him in the middle.
Their defiance ensured Ireland would not only avoid an innings defeat but also give their own attack something to bowl at in Pakistan's second innings.
And, though a ripper from Shadab Khan removed Thompson, O'Brien proved immovable, his belligerent strokes keeping the scoreboard ticking before he wrote his name in the history books by sneaking two through point to bring up his hundred.
O'Brien and Kane withstood pressure from Amir, Rahat Ali and Mohammad Abbas late in the day, and Ireland go into the last three sessions with the unexpected dilemma of deciding how long to bat before attempting to bowl Pakistan out to seal a seismic shock win.
|Gregg Williams is Jets´ new defensive coordinator|
|Ronaldo: Supercoppa triumph just the start for Juve|
|Monaco confirm Batshuayi talks|
|You know more than me! Bielsa´s Barcelona research surprised Guardiola|
|Juventus 1 AC Milan 0: Ronaldo heads Bianconeri to Supercoppa glory|
|Kane injury cannot be excuse for Tottenham – Pochettino|
|Woods to open 2019 schedule at Torrey Pines|
|Reported Liverpool target Dabbur to undergo Sevilla medical|
|Lebanon v North Korea: Radulovic calls on players to make history|
|MLS MVP Martinez signs five-year contract with Atlanta|
|WBC set deadline for Wilder-Fury rematch|
|Iran 0 Iraq 0: Team Melli top Group D after dull draw|
|Vietnam 2 Yemen 0: Quang Hai shines to give Golden Dragons hope|
|Bielsa admits to spying on all Leeds´ opponents|
|Valverde open to arrivals amid De Jong tug-of-war|
|Sexton named in Ireland squad for Six Nations openers|
|Higuain benched for Supercoppa Italiana amid Chelsea links|
|De Grandhomme, Latham and Santner back in Black Caps squad|
|Oman v Turkmenistan: Verbeek tells players to ´score as many as possible´|
|Japan v Uzbekistan: Cuper not distracted by potential last-16 opponents|
|Brown desperate for England recall|
|Lowry ties course record in Abu Dhabi|
|James is playing for Bayern future – Kovac|
|Wizards can compete for playoffs in LeBron-less East despite injuries - Brooks|
|Kyrgyzstan 3 Philippines 1: Lux hat-trick gives White Falcons third-place hope|
|South Korea 2 China 0: Son sets the standard as Bento´s men take top spot|
|Saudi Arabia v Qatar: Top spot on the line in Group E|
|Wasps pull off Fekitoa coup|
|Fresh injury woe for Real Madrid defender Vallejo|
|Home sweet home for Wozniacki as Stephens conquers Melbourne demons|
|Nadal: Victory over Ebden a step forward|
|Proteas rest Steyn and De Kock for opening ODIs|
|Nadal and Federer march on as rising stars prosper|
|Barcelona president Bartomeu convinced Valverde will stay|
|Inter forward Keita suffers thigh injury|
|Nadal races into third round with easy Ebden win|
|Kimmich ´perfect´ for Barcelona, says Xavi|
|Richardson and Nabi inspire Renegades´ rout of Sixers|
|This Liverpool isn´t a team of chokers – Mane|
|Central Coast Mariners 2 Melbourne City 1: Late Simon winner ends 10-match losing streak|
|Bryan backs Murray to return after hip resurfacing surgery|
|Scotland coach Townsend turns to trio of uncapped hookers|
|Spurs´ Aurier arrested on suspicion of assault, released without charge|
|That was a fireworks show - Warriors revel in record-breaking first quarter|
|We are in talks with Chelsea – Salihamidzic reiterates interest in Hudson-Odoi|
|´Proud´ Messi recognises impact of team-mates after reaching 400 LaLiga goals|
|Henry v Vieira: The Arsene Wenger proteges to move into coaching|
|Federer enjoys ´cat and mouse´ win over Evans|
|Wozniacki cruises through in Melbourne|
|Federer maintains perfect Australian Open second-round record|
|Warriors set NBA record, Butler´s 76ers rout Timberwolves|
|´I like the fact we beat them´ - 76ers´ Butler revels in win over Timberwolves|
|Murray says he´ll ´probably´ have operation|
|Australian Open tribute for Andy Murray surprises brother Jamie|
|Warriors score NBA record 51 points in first quarter against Nuggets|
|Panthers owner Tepper doesn´t rule out Newton missing 2019 because of shoulder injury|
|De Ligt will be world´s best centre-back – Koeman|
|Ronaldo a ´perfect machine´, says Gattuso|
|Barcelona? I can´t say anything - Stuani|
|Silva upbeat about Man City title chances|
|Celtics youngsters say Irving´s callout ´came from a good place´|
|NFL playoffs: Patrick Mahomes v Tom Brady|
|NFL playoffs: Jared Goff v Drew Brees|
|Sixers sign Brewer to 10-day contract|
|Lozano and Morgan scoop CONCACAF awards|
|Lakers ´optimistic´ about LeBron injury|
|Giants produce mammoth fourth quarter against Nymburk|
|Austin FC to join MLS in 2021|
|Henry, Vieira look forward to reunion when Monaco host Nice|
|Barcelona reject Neymar phone call reports|