Italy rallied from a two-goal deficit to beat Japan 4-3, earning a spot in the Confederations Cup semifinals.
First-half substitute Sebastian Giovinco scored the winner in the 86th minute of an entertaining match at the Arena Pernambuco, pounding home a cross from Claudio Marchisio.
After a dismal start for the Azzurri that saw Japan score twice in the opening 33 minutes, Daniele De Rossi pulled one back with a header in the 41st.
Japan defender Atsuto Uchida scored an own-goal in the 50th and Mario Balotelli converted a penalty kick in the 52nd.
Japan had taken the lead with a penalty kick by Keisuke Honda in the 21st. Manchester United midfielder Shinji Kagawa doubled the lead for Japan in the 33rd after a defensive error.
Shinji Okazaki made it 3-3 in the 69th with a header in extreme heat.
"The climate was incredible," De Rossi said. "This was one of the toughest matches of my career."
The Azzurri moved even with Brazil at six points atop Group A. Brazil beat Mexico 2-0 earlier Sunday and also advanced courtesy of Italy's win.
In the final round of group matches, Italy will face host Brazil in Salvador, and Japan meets Mexico in Belo Horizonte.
On a warm and humid evening with intermittent rain, the stadium was about three-quarters full with mainly neutral Brazilian fans who were supporting Japan.
"Tonight we really, really struggled," Italy coach Cesare Prandelli said. "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."
For the first half-hour, Italy struggled with defensive errors while Japan controlled the majority of play.
Alberto Zaccheroni, an Italian who took over as coach of Japan three years ago, seemed to know just how to contain Italy.
First, Mattia De Sciglio made a poor back pass to set up Honda's penalty. The pass forced goalkeeper Gianluigi Buffon to tackle Okazaki inside the area.
Buffon protested vehemently that it was a clean tackle, but Argentine referee Diego Abal thought otherwise, pointed to the penalty spot, then showed Buffon a yellow card for protesting.
Italy has struggled with penalties in its last two matches, allowing Mexico an equaliser in its tournament-opener, and yielding a late penalty kick in its 2-2 draw against Haiti in a warm-up game last week.
Next, Giorgio Chiellini mistimed a clearing attempt on a bouncing ball inside the area and Kagawa took advantage by firing in an acrobatic shot.
The 24-year-old Kagawa is quickly becoming Japan's most talented player. In March, he became the first Asian player to score a hat-trick in the English Premier League.
"The idea was to play more or less the way that Barcelona played, a Spanish way of playing," Zaccheroni said.
"You try to apply pressure and retain ball possession as much as possible."
Italy didn't really threaten until De Rossi scored by meeting a corner kick from Andrea Pirlo with a textbook header.
However, De Rossi will miss Italy's next match after picking up his second yellow card in two games.
The goal energised Italy, and Emanuele Giaccherini nearly drew the teams level when he shot off the post in first-half injury time.
The own-goal that made it 2-2 came when Giaccherini attempted to pass to a wide open Balotelli. Uchida intercepted and redirected it into his own net.
Italy went ahead 3-2 on Balotelli's penalty kick following a hand ball by Japan captain Makoto Hasebe.
Using his usual stutter-step technique, Balotelli easily fooled the Japan goalkeeper and improved to 18 for 18 on penalty kicks in his career - with club and country.
Okazaki then beat Riccardo Montolivo for a header to make it 3-3.
After Japan hit the post and crossbar in succession in the 82nd, Giovinco put home the winner following a pass from Claudio Marchisio.
It still wasn't over as Japan had a goal ruled out for offside in the 89th minute.