Photo/Illutration Japan's Timothy Lafaele, right, runs in to score a try during a rugby international between Ireland and Japan at Aviva Stadium in Dublin, Ireland, Saturday, July 3, 2021. (Pool Photo via AP)

DUBLIN--Ireland edged a thrilling back-and-forth match with Japan 39-31 before 3,000 entertained fans at Lansdowne Road on Saturday.

The lead changed five times alone in a breathless first half that Ireland finished 19-17 ahead. Japan then went back in front for a fourth time and threatened a repeat of its historic first win over the Irish at its home Rugby World Cup in 2019.

But Ireland gradually asserted control and managed possession better. While Japan closed to trail just 33-31, Joey Carbery's two penalties gave Ireland a safe buffer against the tiring Japanese with 12 minutes to go.

“(Japan is) a top-class international side, so any type of win was always going to be a great result for us,” happy Ireland coach Andy Farrell said.

"Every single game that we'll play against Japan from now on in will always be a close encounter.”

Japan rued a try disallowed and a penalty hitting the post in the first half.

Ireland was naturally sloppy without 15 regulars either with the Lions, injured, resting or retired. But a second-string team of impressive depth and strength gelled under pressure and made headway with powerful carries, great running lines, and halves who used their forwards’ edge to play with veteran panache.

Jamison Gibson-Park and Joey Carbery were ambitious and rewarded. Carbery, playing his first test since the World Cup after a nagging ankle injury, attacked the line, troubled the Japanese with his kicks, and nailed six of his seven goalkicks.

The Irish spread their five tries among backs Chris Farrell before a head knock, Stuart McCloskey and Jacob Stockdale, and forwards Finlay Bealham and man-of-the-match flanker Josh van der Flier.

Japan, a week after restricting the British and Irish Lions to 28-10, had tries from captain Michael Leitch, center Timothy Lafaele, wing Siosaia Fifita, and scrumhalf Naoto Saito. Yu Tamura converted them all and added a penalty.

“We played some great rugby at times and, for a team that hasn't been together for nearly two years, it's a good sign for us,” Japan coach Jamie Joseph said. “But also it's pretty gutting to have lost that test match.”

Farrell's was the opening try after impressive handling and offloads. Japan replied with Leitch's try from a lineout maul.

McCloskey scored with his second touch after a Carbery kick ahead, and Lafaele, who had a try disallowed after 16 phases because of a forward pass, got it a second time following a crossfield kick to Fifita.

Carbery was held up over the line but Bealham barged over from a tap and go on halftime to put Ireland ahead.

After the interval, Fifita was fastest to a Tamura break and chip to regain the lead for Japan, then Ireland went in front for good following tries to Van der Flier from lineout ball and Stockdale.

A counterattack try finished by Saito between the posts reduced the margin to two but Japan replaced Tamura and Saito and Ireland finished stronger.

“We continued to go after Japan which was the most pleasing thing,” Andy Farrell said. “We managed to stay calm, we managed to stay in control, we managed to stay next-task focused and I think that got us through.”