Maurizio Sarri's team will face holders Bologna in the last eight, thanks to Italy winger Zaccagni heading home Nuno Tavares' corner with 10 minutes remaining in Rome.
Zaccagni's strike handed Milan their first defeat since losing to Cremonese in August, leaving coach Massimiliano Allegri with the Serie A title and the Italian Super Cup to aim for this season.
Milan lead Serie A on goal difference from Napoli, who beat Cagliari in the Cup on Wednesday to also reach the quarters.
Bologna continued their defence with a 2-1 win over Parma, which was decided by Santiago Castro's 89th-minute goal.
The last 16 with be concluded in January when Roma host Torino and Fiorentina take on Como.

