City's victory lifted them five points clear at the top of Group C with three games still to play but there were downsides.
— Manchester City (@ManCity) October 22, 2019
Manager Pep Guardiola may be also concerned about a sluggish start which allowed Atalanta to make a lot of the early running.
Despite their poor record in the competition, the visitors showed the attacking intent that has again lifted them to third in Serie A after finishing in that position last season.
They troubled City in the early stages and could have gone ahead when Robin Gosens chipped a clever cross across goal but Timothy Castagne headed over.
City roused themselves and created a series of good chances. Sterling chipped narrowly wide before failing to find Aguero when well placed.
Aguero forced a good save from Pierluigi Gollini and then shot over after brilliant work by Foden to keep the ball in play on the byline.
City were stung after 28 minutes as Fernandinho, again playing in a makeshift central defensive partnership with Rodri, brought Josip Ilicic down just inside the area. Malinovskyi sent Ederson the wrong way from the resulting spot-kick.
City responded well and were back level within six minutes as Sterling ran across the edge of the box and clipped in a cross for Aguero to calmly tap past Gollini.
The hosts then stepped up a gear and soon claimed the lead with a penalty of their own after Sterling was brought down by Andrea Masiello following another weaving run.
Aguero stroked home the spot-kick and City threatened again as Kyle Walker's deflected shot was turned away by Gollini.
City lost Rodri just before the break with what looked like a hamstring injury but they at least had a specialist defensive replacement in John Stones.
Atalanta offered little after the break and City took a firm grip on the game with a fine team goal just before the hour.
Riyad Mahrez released Kevin De Bruyne down the right and he burst into the area to feed Foden, who in turn teed up Sterling for an emphatic finish from six yards.
Sterling struck again soon after as he raced onto a defence-splitting Ilkay Gundogan pass and wrong-footed a defender to fire home.
Remo Freuler put the ball in the net for Atalanta but was ruled offside before Sterling completed his treble by turning home an inviting Mahrez cross.
Sterling should have had a fourth after racing through one-on-one but rolled his shot wide of the post.
City's night ended on a bad note as Foden, booked harshly moments earlier for a foul, was shown a second yellow card and then a red for pulling back former Middlesbrough midfielder Marten De Roon.