Cardiff restored a three-point lead at the top of the Championship thanks to Craig Bellamy's goal.
Leicester had threatened to overrun their visitors and only a combination of the woodwork and David Marshall's fine goalkeeping denied the Foxes.
But when Cardiff countered, Bellamy dropped off his markers to clip a first-time shot into the bottom corner.
Andy King, in particular, was unlucky not to equalise as Leicester pressed, but Cardiff held firm.
Leicester, looking to consolidate their position in the play-off places, had clicked into gear early and peppered Cardiff's goal.
First David Nugent got free down the right and the Foxes striker hit a crisp shot at goal from a tight angle that Marshall did well to get a hand to.
The Scotland goalkeeper then pulled off a spectacular reaction save from the resulting corner, after Wes Morgan was allowed a free header at the back post.
King then almost punished his countrymen when the Leicester and Wales midfielder saw his curling shot cannon off Marshall's left-hand post.
Jamie Vardy stabbed the rebound against the crossbar, but the striker had already strayed into an offside position.
Anthony Knockaert was the next to test Marshall, the French winger twice sending long-range shots dipping and swerving towards the Bluebirds stopper.
It seemed it would only be a matter of time before Leicester took the lead, but instead Cardiff hit their hosts with almost their first meaningful attack.
Craig Conway did well to stretch Leicester down the right and then pulled the ball back for Bellamy, lurking on the edge of the area, to shoot low across Kasper Schmeichel into the far corner.
Cardiff turned the screw and Morgan did well to tackle Bellamy as he surged into the box, before the former Liverpool striker ballooned the ball over the bar from a tight angle with Schmeichel out of position after punching clear.
The goal against the run of play knocked Leicester's confidence but as half-time approached some of the Foxes' early swagger returned.
King, after surging into the Cardiff half, was unfortunate to see his shot swerve just the wrong side of the post, then Vardy's glancing header clipped the top of the bar.
Leicester again started quickly after the break, but Cardiff almost hit them with a second sucker-punch.
Bellamy did well to shield the ball after chasing down a long punt but his intended lay-off to Heidar Helguson was short, allowing Morgan to make a crucial interception.
Martyn Waghorn came off the bench for Leicester - returning to action just 10 days after having his appendix removed - to replace Vardy and the striker tested Marshall with a lobbed header.
Leicester had another let-off when Rudy Gestede, on for Helguson, stooped to head at goal only to see it deflect over the bar off a defender's shoulder.
Both sides continued to threaten as the game became stretched, although the excellent defensive work of Leicester's Morgan was matched at the other end by Cardiff captain Mark Hudson, back after suspension.
Cardiff could have made the game safe with a swift counter-attack but Bellamy's cross for Aron Gunnarsson was deflected just behind the Iceland international.
Leicester next face a similarly tricky match away to promotion rivals Hull City on Boxing Day, while Cardiff head for home and a clash with another side snapping at their heels in Crystal Palace.
Leicester manager Nigel Pearson: "When you create as many goalscoring opportunities as we did you would expect to score.
"But today we came up against a side that, to be fair to them, defended well and had a lot of experience.
"They hit us with a sucker punch and in the second half it fizzled out a little bit. It was a frustrating day."
Cardiff manager Malky Mackay: "This was a really big win for us after losing to Peterborough and it was smashing the way we bounced back from that. I'm delighted.
"We knew we were coming to play a very good team and that it was going to be tough. But I think this was a great advert for the Championship - and I'm not saying that just because we won.
"It was two teams playing attractive football and at a hell of a tempo."