The English champions were not as their fluent best, but got the one moment of real quality they needed from an unlikely source as centre-back Kompany unleashed a long-range shot into the top corner 20 minutes from time.
City move back one point clear of Liverpool and will become the first side in a decade to retain the title at Brighton on Sunday as long as they match or better the Reds' result at home to Wolves.
After edging past Newcastle 3-2 on Saturday night, Liverpool, who have not won the league since 1990, were left praying that former manager Brendan Rodgers could do them a favour at the Etihad.
Leicester's marked improvement since Rodgers took charge in February was on show in an impressive display from the visitors as City were made to sweat but just got over the line for a vital three points.
Ricardo Pereira scored the winning goal for the Foxes when the sides last met in December and was first to threaten again with a purposeful break into the box before his shot was blocked by Kompany.
City took time to settle, but the hosts began to impose themselves as the first half wore on.
Sergio Aguero came closest to opening the scoring with a header that clipped the inside of the post and was palmed clear by Kasper Schmeichel.
David Silva also flashed a shot across goal and Schmeichel forced into another comfortable save by Bernardo Silva before the break.
Yet, it was not until after the break that City upped the tempo to lay siege on the Leicester goal.
Raheem Sterling headed a glorious chance over then skewed wide as the pressure built.
Leroy Sane was soon thrown on as an extra attacking weapon and Ilkay Gundogan sent another warning shot across the bows of Schmeichel's goal.
Sterling then saw huge shouts for a penalty waived away for a shove by Ben Chilwell, but Leicester had the chance to provoke panic inside the Etihad when Harry Maguire drove forward and fed James Maddison, who curled inches wide.
City thought their moment had come when the ball fell kindly for Aguero inside the area, only for Schmeichel to make a miraculous stop.
Guardiola's men have now scored 157 goals this season but there will not be a more spectacular or unexpected one than that which may deliver the title.
Kompany looked short of options as he strode forward before unleashing a rocket of a shot that arrowed into the top corner.
Leicester still had a huge chance to answer Liverpool's prayers three minutes from time, but against his former club Kelechi Iheanacho shot wide with just Ederson to beat and a titanic tussle for the title remains in City's hands heading into the final day.