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.
|Pedroia to return for Red Sox on Friday|
|Warriors´ Iguodala ruled out for game five against Rockets|
|Na leads as Spieth makes solid start at Colonial|
|James Harden, LeBron James headline 2017-18 All-NBA first team|
|Manchester United target Fred to decide future after World Cup|
|´Incredible´ Salah is like Messi, says Ronaldo|
|Salah a big candidate for Ballon d´Or - Muller|
|Message from coach keeping Masters champion Reed grounded|
|Anybody can really win it - Seles feels French Open is wide open this year|
|Mambo number 5! - Non-league star channels Lou Bega hit|
|Pakistan to stop wearing smart watches after ICC intervention - Hasan|
|Saha hails ´great man´ Ferguson as legendary Man Utd boss continues recovery|
|Emery´s depth of knowledge impressed Arsenal´s Gazidis|
|Conceicao extends Porto contract|
|Lomax impresses as Saints overrun Tigers|
|McIlroy in contention at Wentworth as Bjerregaard sets the early pace|
|Bad light calls time on Thiem, Wawrinka out in Geneva|
|Garitano in, Canales out at Real Sociedad|
|Caparros accepts new role at Sevilla|
|Pliskova downed by Larsson after drawing Serena in Paris|
|They´re using the anthem as fake patriotism - Warriors coach Kerr critical of NFL|
|Lyon win record fifth Women´s Champions League title|
|French Open 2018: Doing the unthinkable - the men most likely to topple Nadal|
|French Open 2018: How can Rafael Nadal be stopped?|
|Steve Smith named as marquee player for Global T20 Canada|
|Can Emre play? Yes he Can... and so can Milner|
|Liverpool working to help fans after flight cancellations|
|Abbas and Hasan torment sorry England|
|Xavi ´thrilled´ to sign two-year Al Sadd extension|
|Holtby extends Hamburg contract despite relegation|
|Nadal begins French Open defence against Dolgopolov|
|Serena drawn to play Pliskova in French Open first round|
|FA condemns assault of match official|
|Bologna confirm Donadoni departure|
|Yates lead halved in Giro d´Italia|
|Connacht turn to Friend|
|Scotland lose injured Dunbar for June tour|
|Spalletti in ´no rush´ to sign new Inter deal|
|Ricciardo and Red Bull dominate Monaco practice|
|Mauricio Pochettino signs new deal with Tottenham|
|Pochettino signs new deal with Tottenham|
|Istanbul to host 2020 Champions League final|
|Williams sisters given French Open wildcard|
|President Donald Trump praises NFL´s anthem stance|
|Buffon in consideration for Italy call, says Mancini|
|Roberts injured in Broncos win against Eels|
|Atletico complete move for Villarreal star Rodri|
|Ozil, Gundogan not playing politics, says Low|
|Valencia complete permanent Kondogbia signing|
|Fairytale ending could be in the script, says World Cup-bound Vardy|
|Milwaukee police apologise to Bucks´ Brown over tasering|
|Television, crosswords and Nintendo - Koscielny´s remedy to World Cup heartache|
|World Cup not an audition for Barca or Madrid, says Germany star Werner|
|Neck injury rules Kohli out of Surrey stint|
|Nine LaLiga titles and 674 club games under nine managers - Iniesta in Opta numbers|
|49ers Enterprises takes stake in Leeds United|
|Manchester United should sell Pogba if he´s unhappy - Scholes|
|Andres Iniesta´s nine LaLiga triumphs with Barcelona|
|Andres Iniesta: The footballers´ footballer|
|Real Madrid v Liverpool: Salah has foundations in place for Ballon d´Or challenge|
|Iniesta´s Vissel Kobe move confirmed|
|Low upbeat over Neuer´s World Cup hopes|
|´No secrets´ in playoffs, says Celtics rookie Tatum|
|Real Madrid v Liverpool: Salah takes his chances better than Ronaldo - Opta|
|Cubs, Yankees find very different ways to lose|
|Cole hoping to see Rooney in MLS amid DC United links|
|LeBron feeling worn down following Cavs loss|
|Rahm enjoys ´traditional golf courses´|
|Upbeat Spieth eyeing first win of 2018|
|Ovechkin leads Capitals into Stanley Cup Finals|