HOUSTON - Japan came close to making history but suffered a heartbreaking 2-1 defeat to Brazil at the death in the World Cup round of 32 on Monday, falling short of their first-ever knockout-phase win at the tournament.

Kaishu Sano scored a 29th-minute opener for Japan, but Casemiro leveled with a 56th-minute header and Gabriel Martinelli netted the winner for the five-time champions in the fifth minute of stoppage time at Houston Stadium.

Japan manager Hajime Moriyasu could not get the better of Carlo Ancelotti, his revered Italian counterpart, for a second time after Japan claimed a 3-2 comeback win over the Selecao in a friendly in Tokyo last October, their first win over Brazil at senior level.

The Samurai Blue lost to Brazil for the second time at the World Cup after going down 4-1 to the Ronaldo-inspired South Americans in their only previous matchup in the 2006 group stage in Germany.

Ritsu Doan kept the captain's armband as Ko Itakura was left on the bench by Moriyasu, who restored Takehiro Tomiyasu on the right of Japan's back three to mark the in-form Vinicius Jr.

Sano and Casemiro both received early bookings in a tense start and Cunha tested Japan keeper Zion Suzuki with a low drive before Sano, whose clumsy challenge inside his own box moments earlier was waved away, netted a superb solo goal.

The Mainz midfielder intercepted a pass on the halfway line, skipped past Casemiro and drove into space before drilling into the left bottom corner of the net from 25 meters out, beyond the outstretched arm of Brazil keeper Alisson.

Japan dominated proceedings until the break, but Suzuki needed a diving save to deny Bruno Guimaraes's header, before Cunha's effort somehow stayed out after ricocheting off Tomiyasu's face and the Samurai Blue keeper's head.

It was a case of third-time lucky for the Brazilians, however, as Gabriel Magalhaes' deep cross from the left was headed in by Casemiro, and the South Americans continued to pile on the pressure, with Vinicius Jr. dancing into the area before hitting the far post.

Moriyasu brought on Yukinari Sugawara and Junnosuke Suzuki to add steel in both wing-back positions as Japan looked to see out the second half, but Martinelli had the last say as his shot from inside the box went in off the right-hand post.

Japan advanced to the knockout stage four times from their past seven World Cup appearances but lost in the round of 16 each time, in normal time to Turkey (2002) and Belgium (2018), and on penalties to Paraguay (2010) and Croatia (2022).

Brazil were the first former World Cup winners to meet Japan in the knockout phase. The South Americans will face either Norway or Ivory Coast next.

Related coverage: