Kevin O’Brien wrote a fresh chapter in cricket’s record books by becoming the first Ireland batsman to score a Test century as the hosts turned their debut in the format against Pakistan upside down at Malahide on Monday.

In danger of an innings defeat after being made to follow-on in their inaugural men’s Test, Ireland ended the fourth day on 319/7 in their second innings – a lead of 139 runs – with O’Brien 118 not out.

This was O’Brien’s first hundred for Ireland in all formats since he hit the all-time fastest-ever World Cup century by any batsman, off 50 balls, against England at Bangalore in 2011.

And it meant Ireland had a shot at becoming just the fourth side in the 141-year-history of Test cricket to win a match after following-on.

“It’s a very proud and emotional moment,” O’Brien told reporters after stumps, having batted for five hours and 40 minutes on Monday.

“To get there, it’s a great honour. Hopefully now we’ve put ourselves in a good position to go and win it.”

Asked to compare this innings with his World Cup ton, the 34-year-old replied: “I still think for me Bangalore is definitely number one, just for the sheer moment it was and against who it was, in the World Cup.”

Ireland were 95 for four when O’Brien, who top-scored with 40 in their first-innings 130, walked into bat on Monday.

But as well as his own composed strokeplay, O’Brien had support from Stuart Thompson in a seventh-wicket stand of 114.

Sarfraz Ahmed became the first Pakistan captain to enforce the follow-on in a Test in 16 years when he sent Ireland back in again on Sunday, a move that may have seen the tourists victorious by now had Ireland openers Ed Joyce and William Porterfield not both been dropped in single figures off Mohammad Amir on the third day.

Ireland were also helped by the fact that Amir, who earlier on Monday took his 100th Test wicket, was off the field for much of the day’s final session as he struggled with the recurrence of a knee injury that had flared up again on Sunday.

Ireland resumed on 64 for none but they lost four wickets before lunch, with Amir taking two for none in six balls – a heartening sign for Pakistan ahead of their two-Test series in England that will feature back-to-back fixtures at Lord’s (May 24-28) and Headingley (June 1-5).

Ireland gifted Pakistan an early breakthrough when Joyce ran himslf out for 43 after failed to beat Faheem Ashraf’s shy from midwicket.

Fears that as soon as Ireland lost one wicket, another would follow quickly, were proved correct as 69 for one became 69 for two, with Andrew Balbirnie, for the second time in the match, was lbw to Mohammad Abbas for nought.

Amir was on target for the first time on Monday when Niall O’Brien, Kevin’s brother, had his stumps uprooted – a wicket greeted with the bowler’s familiar arms outstretched celebration.

And 94 for three became 95 for four when Porterfield (32) edged Amir to wicket-keeper Sarfraz.

Amir, given a jail sentence and banned from cricket for five years as a result of his involvement in a spot-fixing scandal during the 2010 Lord’s Test, took his 100th wicket in 31 matches at this level when Gary Wilson was held in the slips by Haris Sohail.

But Thompson’s single off all-rounder Faheem meant Pakistan would have to bat again.

Pakistan took the new ball but it was leg-spinner Shadab Khan, not the pacemen, who struck next when he turned one sharply to bowl left-hander Thompson for 53.

O’Brien went steadily through the 90s before a pushed two off Amir saw him to a 186-ball hundred including 10 fours, the batsman punching the air in celebration.

Pakistan’s fielding became increasingly sloppy but shortly before the close O’Brien, on 118, almost played on to Amir.

But if anyone deserved the traditional luck of the Irish, it was O’Brien.