Attacks came thick and fast towards the end for City and eventually their persistence paid off, with Sterling bundling home a rebound to maintain the eight-point gap at the top of the table and secure an 11th consecutive league win.
City were made to work hard for all three points after they went in at the break 1-0 down when Argentina global Nicolas Otamendi deflected a corner into the back of his own net.
City have been in stunning form with 37 points from a possible 39 this season and are unbeaten in 26 matches in all competitions stretching back to last term.
Nicolas Otamendi was unfortunate as he scored an own goal to give Huddersfield the lead and City went into the break trailing.
Three new Marvel vs. Capcom: Infinite characters dated
Capcom: Infinite Collector's Edition, brought to you by TriForce, is available now for pre-order on PS4 and Xbox One. A new trailer has been released showing off Black Widow , Venom , and Winter Soldier in action.
Sterling won City a spot-kick in their victory over Arsenal earlier this month, which resulted in Wenger claiming the 22-year-old "dives well", but Guardiola dismissed suggestions the former Liverpool man had exaggerated the contact on either occasion.
Guardiola, whose side have dropped points in just one of their 13 Premier League games this season, said: "We said that we needed this situation to happen - you have to live it, to be in trouble".
'The corrections from the first half were minimal because we played quite good - we created more chances than in the second half but that is the Premier League for you. We have a lot of games, we will see what team we can play in the final game.
"It was a brilliant move to win the penalty. The guys competed amazingly, which is why we won". It is impossible to win every game easily, this league is so tough.