Japan kept their dreams alive of a place in the quarterfinals of the Rugby World Cup on Saturday with a 38-19 bonus-point win over Samoa at City of Toyota Stadium.

A somewhat nervy display finished in bizarre circumstances with Kotaro Matsushima crossing for Japan's fourth try in the 84th minute after Samoa had opted for a scrum on their own line rather than take a free kick.

The move backfired when the Pacific Islanders were then penalized for a crooked feed and from the resulting scrum, Matsushima sprinted over to add to earlier efforts by Timothy Lafaele, Kazuki Himeno and Kenki Fukuoka.

The victory sees Jamie Joseph's side head into the final weekend of Pool A action on top of the standings and with their destiny in their own hands.

(Kenki Fukuoka of Japan runs with the ball on his way to score a try.)

(Kotaro Matsushima (L) of Japan fends off a Samoa player.)

Japan have 14 points, Ireland 11 and Scotland, who have played one fewer game, five.

Japan's final pool game is against Scotland on Oct. 13, four days after the Scots have played Russia, and the Brave Blossoms go into the fixture knowing a single point could be enough to make the quarterfinals, though mathematicians will be working all week to work all the various permutations given Ireland's final pool game is against Samoa a day earlier.

The defeat means Samoa, like Russia, cannot advance to the quarterfinals, while Japan cannot finish worse than third in the pool, ensuring automatic qualification for the 2023 World Cup in France.

"That was a never-die attitude," said Joseph. "We knew that was going to be a real physical battle, and Samoa never let us down. They were quite impressive, particularly because they played a test four days ago."

His opposite number Vaeluaga Steve Jackson was gracious in defeat but said he felt the Samoans were on the wrong end of a number of decisions from the officials.

"We didn't deserve some of the things that went on out there and I am gutted for the players," he said.

In front of 39,695 fans, it took Japan just two minutes to get the scoreboard ticking over as Yu Tamura slotted over a penalty.

The flyhalf doubled the lead five minutes later as Japan's kicking game worked to perfection with the chasers regaining possession to set up the field position from which Tamura slotted his second penalty.

Following that ideal start, however, Japan went off the boil, and two penalties from Henry Taefu saw the sides level with 15 minutes on the clock.

(Yu Tamura of Japan kicks a penalty.)

A third penalty from Tamura saw Japan regain the lead but with the crowd strangely muted, the Brave Blossoms needed something to fire them up.

It came in the shape of Matsushima, whose electrifying burst -- a few minutes after Samoa flanker TJ Ioane had been sin binned for a late tackle on the wing -- eventually saw Lafaele cross for the opening try of the game.

A third Taefu penalty in the 33rd minute put seven points between the teams and ensured Samoa restricted the damage while Ioane was off the field as the teams turned around with Japan leading 16-9.

That damage control was in part because of unforced errors from the hosts, who seemed to resemble the nervous side of the opening night win against Russia rather than the side that shocked Ireland a week ago.

Japan gave up as many penalties in the first half as they did in 80 minutes against Ireland and turned the ball over seven times. And the second half started with more of the same.

"We were a bit frantic in the first half," admitted Joseph.

A fourth penalty from Taefu made it a four-point game shortly after the restart before Tamura banged over one of his own in the 51st minute.

Three minutes later, the crowd erupted as a perfect driving maul from a line-out saw local favorite Himeno, who plays for Toyota Verblitz, touch down.

The score should have settled everyone down but errors still abounded and a try by Taefu, that the center converted himself, once again made it a seven-point game.

Japan, however, dug deep, with replacements such as Fumiaki Tanaka and Isileli Nakajima and Fukuoka imposing themselves on the game.

Fukuoka made the most of some good work by his forwards to sprint over before Matsushima made the most of Samoa's decision and scrum infraction to sprint over and secure the bonus point and ensure the Brave Blossoms' quarterfinal dream remains very much alive.

"I thought our scrum was doing well at the time and we back our team to score from anywhere," Samoa captain Jack Lam said of his decision that if it had panned out could have seen Samoa come away with a bonus point of their own for losing by less than seven.

"It was hard work out there," said Japan captain Pieter Labuschagne. "It took us a long time, they're a good quality side and they showed it, especially in the first half, it went a bit see-saw. But luckily in the last minute we got a bonus-point try so I'm delighted about the result."

Related coverage:

Rugby: Japanese superfan takes spotlight with body-painted jerseys