Andriy Shevchenko put Milan ahead with a superb strike on 77 minutes after Emerson's dismissal for two yellow cards 11 minutes earlier.
Lazio's Mauro Zarate scored the equaliser from the spot three minutes from normal time after Giuseppe Favalli fouled Pandev.
The Macedonia striker then netted a rebound two minutes into the first extra period to set up a clash against Fiorentina or Torino in January and February's last eight.
Milan, who lost 3-1 at Palermo in the league on Sunday, started with Kaka and Ronaldinho for the club's first appearance in this season's cup but also fielded reserve goalkeeper Dida.
The match was the only cup game this week with the last 16 round spread over three months because of fixture clashes.
Napoli, Udinese and Sampdoria are already through to the quarter-finals having won their ties last month while holders AS Roma entertain Bologna and Fiorentina host Torino on December 17.
Serie A leaders Inter Milan welcome Genoa on January 13 and Juventus wrap up the round with a home tie against Catania on January 14.