Kagawa swivelled and volleyed home a bouncing ball with his left foot to send Japan 2-0 up on 33 minutes after Keisuki Honda's earlier penalty.
But Japan then conceded three goals in the space of 11 minutes - straddling the half-time interval - to find themselves 3-2 down. First, Daniele De Rossi powered a bullet header into the net before the break. Then an Atsuto Uchida own goal and a Mario Balotelli penalty handed the Azzuri the advantage.
The see-sawing match took another twist when Shinji Okazaki headed home a wide free-kick on 69 minutes to level the scores before Juventus forward Sebastian Giovinco netted the winner with four minutes remaining.
The result means Kagawa's Japan are now out of the competition, with Italy and hosts Brazil progressing to the semi-finals from Group A.
Afterwards, Shinji told reporters he felt Japan should have won the game.
"We were leading the match 2-0," he said. "We could have made it 3-0 or 4-0.
"What was worse, though, was that we let them score at the beginning of the second half. It was hard to take that we conceded goals due to silly mistakes.
"However, we came back and were able to tie the score from the set-piece. Italy scored in the last few minutes but we also had more chances to score. That was the big difference: Italy didn't miss any chances."