Massimiliano Allegri's Milan, already in the last 16 of the Champions League by finishing second, made eight changes to the side that won 3-1 at Catania in Serie A on Friday.
They still dominated the match but, apart from a penalty appeal after four minutes when Giampaolo Pazzini seemed to be fouled by Bruno Alves, Milan created few chances until they brought on their first choice strikers late in the game.
Zenit opened the scoring after 35 minutes when Danny snapped up a loose ball from a weak tackle and stroked home the decisive goal that ensured the Russian side finished above Anderlecht, who came bottom of the group after a 2-2 draw at Malaga.
Milan came close to equalising in the 73rd when Bojan Krkic embarked on a fine piece of dribbling but let the ball run away from him just before he could shoot and the resulting clearance flew past Pazzini's outstretched leg.
Milan brought on their Brazil forward Robinho and Serie A top scorer Stephan El Shaarawy to try to get something from the game and they each had a chance to level the score.
Robinho went close with a curling right foot strike after 83 minutes and two minutes later El Shaarawy dragged an effort wide with his left foot but it was too little too late.
Zenit held on for the win that secured third spot in the group and a place in the Europa League with seven points, one behind the Italians and two ahead of Anderlecht. Champions league debutants Malaga topped the group with 12 points.
"I'm disappointed that we lost, but the team played well. We conceded the goal from the first chance we gave them," said Allegri.
"They committed 10 more fouls than us and when you commit more fouls it means that you're nearer the ball, in for more tackles.
"We might have had more of the ball, but when it came to tackles we weren't aggressive enough and, in fact, that's how they scored their goal."
Milan midfielder Mathieu Flamini, who started only his fourth game this season, added: "It's a shame because we played well, created chances but couldn't get that shot away.
"We're disappointed because we created the play, we kept the ball well but they scored that goal after which they put themselves behind the ball and played defence."
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.