Gabriel Jesus was Manchester City’s star performer with a hat-trick that made it 500 goals in an impressive 199 games of Pep Guardiola’s management. “It’s nice, these four years together we’ve had fun and an incredible amount of good moments. Hopefully we can [do] 500 more – in two months,” said the manager, joking.

Jesus said: “When I was young, I’d think about the Champions League. It’s a very special moment when I score and a hat-trick as well.”

Bayern Munich v Tottenham Hotspur: Champions League – live! Read more

With Phil Foden pulling the strings – and Dinamo Zagreb around – from midfield Jesus had admirable support on a night when Benjamin Mendy also gave a reminder of why he was signed.

City were already in the last 16 as Group C winners but required a morale-boosting victory after a dire run of form. For this challenge Guardiola retained Rodri, Jesus and Ilkay Gündogan from Saturday’s loss to Manchester United, made Foden’s 50th City appearance a fourth start this term and handed Eric García a full debut in the competition.

All that meant this outing might not be the best barometer of form and mood. Yet the way Nicolás Otamendi lost Dani Olmo before he volleyed Damian Kadzior’s ball past Claudio Bravo was the latest addition to a catalogue of defensive calamities. The finish was supreme but caused more questions regarding a rearguard who have now kept one clean sheet in their past 12 matches.

For a packed Stadion Maksimir this was the dream beginning – City fans apart – as Zagreb required victory to retain any chance of qualification. For the visitors it was poor, but Foden zipped the ball through midfield allowing City to launch the quick attacks Guardiola desires.

Quick guide Roundup: Atalanta stun Shakhtar to qualify Show Hide Atalanta won 3-0 away to Shakhtar Donetsk to take second place in Group C – despite losing their first three group games by an aggregate score of 11-2. Needing a win to progress with Dinamo Zagreb losing to Manchester City, the Italian side went ahead in the 69th minute when Timothy Castagne poked the ball home at the second attempt. Shakhtar's chances of an equaliser were hit by a red card for Dodo, before late goals from Mario Pasalic and Robin Gosens sealed an unexpected last-16 place in their debut Champions League campaign. PSG completed a dominant group stage with a 5-0 win over Galatasaray, with five different players finding the net. Mauro Icardi, Pablo Sarabia, Neymar and Kylian Mbappé all struck before Edinson Cavani's late penalty. Elsewhere in Group A, Real Madrid were pegged back by Club Brugge before goals from Vinícius Júnior and Luka Modric sealed an away win. Rodrygo's half-volley put the visitors ahead early in the second half, before Hans Vanaken equalised two minutes later. Juventus completed an unbeaten Group D campaign with a 2-0 win at Bayer Leverkusen. Late goals from Cristiano Ronaldo and Gonzalo Higuaín – both set up by Paulo Dybala – and Atlético Madrid's win over Lokomotiv Moscow ended Leverkusen's faint hopes of qualifying. In Group B, Olympiakos defeated Red Star Belgrade 1-0 to snatch a Europa League place in a game of two penalties. Tomané missed his spot-kick for Red Star, before Youssef El Arabi converted late on for the hosts. Photograph: Sergei Supinsky/AFP

An angled pass to Mendy allowed the left-back to whip in a cross that had Jesus leaping and Dominik Livakovic punching away just in time.

Olmo may have scored once more when running through – Otamendi again could not get near him – but he blasted his shot over. Next Olmo’s flick found Mislav Orsic and this time Bravo saved the header.

Dinamo Zagreb 1-4 Manchester City: Champions League – live! Read more

What City had lacked in the run of two wins in seven matches was quality in the boxes, as Guardiola says. An illustration of what was required came via the equaliser. Riyad Mahrez swept the ball into the back post from the right and Jesus was lethal with his head: simple and effective. That made him the youngest Brazilian, at 22 years and 252 days, to hit 10 Champions League goals, beating Neymar’s previous mark.

The goal angered Zagreb, though, as Emir Dilaver had gone down during the build-up but while players surrounded Carlos del Cerro Grande, the referee ruled it legitimate and booked Arijan Ademi for his part in the protest.

Facebook Twitter Pinterest Arijan Ademi of Dinamo Zagreb argues with Gabriel Jesus after the Brazilian’s equaliser. Photograph: Michael Zemanek/BPI/Shutterstock

This was an admirable riposte from City in a hostile venue and ensured the score was level at half-time: the break came at an apt time as the ill-feeling continued when Amer Gojak may have been sent off, but was not even booked, for an elbow on Rodri near the touchline.

At this juncture City were ensuring unbeaten progress to the next round and Zagreb were going out. Yet City pride themselves on winning intent and this was signalled by a Foden shot that, although high, warned their hosts.

Next they carried the threat through via some delightful footwork from Jesus. Foden’s slick ball-play put the striker in near goal and after some Fred Astaire-like feet he allowed Livakovic no chance with his finish.

This had Guardiola double-fist pumping and posed a question of Zagreb they would surely find difficult to answer. So it proved as the excellent Foden fed Mendy and his equally impressive cross was stabbed in by Jesus for his third.

From here it was a keep-ball exercise for City before Foden scored a deserved late fourth for a team who could be proud of the character shown.

On Monday, City will find out who they face. “We will all watch the draw together,” said Guardiola. “This competition is weird but hopefully we arrive in good spirits in February.”