Right back Joshua Kimmich found Goretzka with a defence-splitting pass deep into stoppage time and the Germany midfielder coolly slotted the ball past Gianluigi Donnarumma to give the club a second win in the exhibition competition.
Milan had their chances in the second half, not least when Patrick Cutrone was put through one-on-one with Sven Ulreich only to be denied by the goalkeeper, but could not find an equaliser on a warm night in Kansas City.
'Better but not recovered' – The story behind Juve's 'horrible results' - Inside Europe
The match was Milan's first since head coach Marco Giampaolo took the helm at the Serie A club, who parted ways with Gennaro Gattuso at the end of last season.
Next up for Bayern Munich is a semi-final clash with Turkey's Fenerbahce on Tuesday while Milan face Portuguese outfit Benfica on Sunday.
Coman has minor heart surgery, set to miss two weeks
Klopp: Liverpool got 'carried away' before thrilling fightback