Mexico had come from behind three times to send the game into
extra-time at 3-3 but in the 97th minute Ballack swerved a
free-kick from the edge of the area past Oswaldo Sanchez.
Germany were relieved after throwing away the lead three times,
and it could have been four had Luis Perez not blazed a shot wide
in the final minute.
Striker Mike Hanke was sent off in the 54th minute for a late tackle. In what was supposed to be a friendly match Hanke clattered into Carlos Salcido with the ball long gone and received a straight red card for his petulance.
At the time of the incident Germany led 2-1 thanks to goals from
Lukas Podolski (37min) and Bastian Schweinsteiger (41) but Mexico
equalised again through Jared Borgetti after 58 minutes.
Robert Huth then put Germany in front for the third time in the 79th minute but Borgetti equalised with a bullet header six minutes later.
But it was Ballack who had the final say scoring his fourth goal
in this competition - the other three have been penalty kicks.