Italy completed a superb fightback to knock Japan out of the Confederations Cup and book their place in the semi-finals in a hugely entertaining game.
Japan went 2-0 up via Keisuke's Honda's penalty and Shinji Kagawa's strike.
But Italy responded in some style when Daniele De Rossi headed in before Atsuto Uchida's own goal and Mario Balotelli's penalty made it 3-2.
Japan equalised through Shinji Okazaki and also hit the woodwork, before Sebastian Giovinco sealed it for Italy.
Alberto Zaccheroni's Japan side could be justified in feeling the result in Recife was harsh on them.
Having surrendered a two-goal lead, then recovered from going behind to bring the scores level again after 69 minutes, they saw Okazaki and Kagawa hit post and bar respectively with eight minutes left.
"Japan were truly terrific and deserved to win but fair play to Italy for showing resilience to come back and win the game.
"Keisuke Honda is on a free transfer, wow, there will be a number of clubs after him. What a competition and what a game - the match of the tournament so far."
So when Giovinco - a first-half substitute for Alberto Aquilani in an opening period dominated by Asia's champions - popped up to tuck in Claudio Marchisio's cross four minutes from time it was a crushing blow for the team that had showed the greater enterprise over 90 minutes.
The result ends Japan's involvement here but the Brazilian crowd lapped up their quick passing and movement and will welcome them back to next year's World Cup, for which they have already qualified.
Ultimately Cesare Prandelli's earned the win through a ruthlessness Japan could not match, and they join Brazil in the last four as qualifiers from Group A. But they struggled to begin with as Manchester United's Kagawa - a potential star of next year's global showpiece - created countless problems for the normally resolute Italian backline.
Japan looked a completely different side to the one that lost to Brazil in their opening match, their passing fluid and their tempo higher than the Italians.
The breakthrough was a gift, however, as Mattia De Sciglio left his backpass short and Gianluigi Buffon was adjudged, perhaps harshly, to have brought down Okazaki. The keeper was shown a yellow card and Honda scored the spot-kick.
With Italy being outplayed, Giovinco's early introduction was an attempt to give more balance to Prandelli's side. But Kagawa gave Japan the more emphatic lead they deserved when he fired in a shot after the Italian defence failed to deal with Yasuyuki Konno's looping ball into the box.
Asia's pass masters?
Japan attempted 349 passes in Italy's half - only Spain have attempted more in the opposition half during the Confederations Cup (523).
De Rossi was then booked - he will miss the final group game against Brazil - as the Italians looked in danger of falling apart. But out of nowhere, the Roma midfielder led a surprising Italian turnaround before the break.
First, he headed in Andrea Pirlo's corner after 41 minutes, before Emanuele Giaccherini hit the post in first-half stoppage time. And five minutes after the interval Italy got the equaliser they sought when Uchida knocked the ball into his own net after Giaccherini's persistence.
The Azzurri's revival continued when Argentine referee Diego Abal awarded a second contentious spot-kick, penalising Japan captain Makoto Hasebe for a handball despite the ball bouncing off the floor to hit him from Giaccherini's shot.
Balotelli produced his customary stuttering run-up then stroked Italy into a scarcely credible lead.
But in sweltering conditions, the Italians seemed to fade again and paid the price when Okazaki nodded home Yasuhito Endo's free-kick as the game swung once more.
Japan were inches away from winning it as Buffon's goal led a charmed life, but Giovinco added the final twist as Italy rejoiced.
Even then Japan almost equalised again but Maya Yoshida's effort was ruled out for offside after Okazaki's shot had come back off the bar.
Italy coach Cesare Prandelli:
"Tonight we really, really struggled. We need to deal with the climate, it's really difficult. But I liked the way we suffered. We could have felt satisfied with ourselves but instead we wanted the win."
- 01 Buffon Booked
- 02 Maggio (Abate - 59' )
- 03 Chiellini
- 05 De Sciglio
- 15 Barzagli
- 07 Aquilani (Giovinco - 30' )
- 16 De Rossi Booked
- 18 Montolivo
- 21 Pirlo
- 22 Giaccherini (Marchisio - 68' )
- 09 Balotelli
- 12 Sirigu
- 13 Marchetti
- 04 Astori
- 19 Bonucci
- 20 Abate
- 06 Candreva
- 08 Marchisio
- 17 Cerci
- 23 Diamanti
- 10 Giovinco
- 11 Gilardino
- 14 El Shaarawy
- 01 Kawashima
- 05 Nagatomo
- 06 Uchida (Sakai - 73' )
- 15 Konno Booked
- 22 Yoshida
- 04 Honda
- 07 Endo
- 10 Kagawa
- 17 Hasebe Booked (Nakamura - 90' )
- 09 Okazaki
- 18 Maeda (Havenaar - 79' )
- 12 Nishikawa
- 23 Gonda
- 02 Inoha
- 03 Sakai
- 16 Kurihara
- 21 Sakai
- 08 Kiyotake
- 13 Hosogai
- 14 Nakamura
- 19 Inui
- 20 Takahashi
- 11 Havenaar
Ref: Diego Abal