Cesare Casadei marked his Leicester debut with a stoppage-time winner after Aaron Ramsey had threatened to derail the Foxes' 100% start to the season.
Casedei, signed on loan from Chelsea on Wednesday, made an instant impact to make it four wins out of four for new Foxes manager Enzo Maresca. No Leicester side had previously managed such a feat at the start of a season.
Ramsey's first Cardiff goal since 2011 cancelled out a fine debut senior strike from Wanya Marçal-Madivadua, Leicester's 20-year-old Portuguese winger.
Cardiff, still winless in the Championship under new manager Erol Bulut, saw defender Mahlon Romeo sent off before the final whistle.