YOKOHAMA, Japan (AP) — Japan got the chance to prove it was a worthy Rugby World Cup quarterfinalist and took it bravely with a 28-21 win over Scotland on Sunday to bring some joy to a host country reeling from a ferocious typhoon overnight.

The tournament host swept Pool A and will play South Africa next week. And it has form against the two-time champion, after producing the so-called Miracle of Brighton to upset the Springboks in 2015.

After a stirring comeback, Scotland misses the quarterfinals for only the second time and will go home.

Japan is into the knockout stage for the first time, fittingly in the first Rugby World Cup staged in Asia.

Ireland placed second in the group and will play the defending champion All Blacks next week.

Winger Kenki Fukuoka scored a try in the first half and touched down again three minutes after the break to secure Japan a four-try bonus point with almost half a game to play at a Yokohama Stadium packed with 72,000 people almost entirely wearing red-and-white striped shirts.

But then the game that almost didn’t happen because of Typhoon Hagibis become a classic.

It was Scotland that ended Japan’s hopes of a quarterfinal run four years ago. And the Scots rallied from a 31-0 deficit to draw with England in the Six Nations this year.

Japan led 21-7 at halftime with three tries after Scottish flyhalf Finn Russell strolled through some weak defense in the seventh minute. The new half had barely started when Fukuoka stripped the ball from Chris Harris and ran away to extend the lead to 28-7.

That’s when Scotland threw caution to the wind. Two tries in six minutes to front-rowers Willem Nel and Zander Fagerson narrowed the gap to seven points and set up a tension-filled last 25 minutes.

Both teams threw everything into attack and defended grimly. The Scots repelled 22 phases from Japan on the hour before a relieving penalty. But Scotland, needing a win to have any chance of advancing, just couldn’t crack Japan’s defense, either.

Three minutes from fulltime, first-half hero Kotaro Matsushima accidentally carried the ball back over his line, giving Scotland a five-yard scrum and a chance to equalize. But the Japanese defended their line, won back possession and wound down the clock.

The game that caused so much angst for organizers was green-lit only on Sunday morning after the stadium was assessed and local authorities confirmed transport would be running again after cancellations on Saturday, when the typhoon made landfall.

The players from Japan and Scotland lined up on the field and, for a minute, the capacity crowd went silent.

That was to pay respects for the dead and injured from the ferocious typhoon. From the national anthems on, the noise didn’t stop until well after fulltime. Then the celebrations really got underway.