Malky Mackay's Carling Cup finalists suffered back-to-back league defeats for the first time this season as they followed up last week's 3-1 loss at home to Blackpool with a largely abject display.
Only the inspired form of Cardiff goalkeeper David Marshall kept Leicester at bay until Gallagher - who replaced the suspended Neil Danns in the Foxes' only change - opened the scoring with a penalty four minutes before half-time.
Kenny Miller thought he had levelled moments after, only to be denied by the offside flag.
In a quieter second half, Gallagher found the decisive goal with a superb free-kick before Peter Whittingham reduced the arrears from the spot.
Leicester move to within six points of the play-offs while Cardiff remain fourth but slip five points behind second-placed Southampton.
The hosts started impressively as Jermaine Beckford came within inches of finding the decisive touch on Daniel Drinkwater's cross before Gallagher sliced wide from Lee Peltier's knockdown.
Cardiff then suffered a setback in the seventh minute as Aron Gunnarsson hobbled off with a suspected groin injury to make way for Filip Kiss and Mackay's men continued to struggle in finding an answer to Leicester's early momentum.
Beckford engineered space on the right wing for Gallagher to cross and Richie Wellens aimed an overhead kick, which took a deflection to force a fine save from David Marshall in the Cardiff goal.
Gallagher's delivery was becoming an increasing problem for the visitors and centre-backs Sean St Ledger and Matt Mills went close following set pieces from the former Blackburn man.
Marshall was called into action with half an hour gone to save from Beckford on the angle following some clever interplay with strike partner David Nugent and moments later the ex-Leeds forward shot wide when Anthony Gerrard misjudged a searching ball from Gallagher.
Wellens produced an excellent half-volley from 30 yards for Marshall to push over at full stretch but, when the midfielder was felled by Kiss, Leicester had the lead they deserved in the 41st minute.
The infringement came from another Gallagher corner and the winger proved himself to be just as effective from the penalty spot, finding the bottom corner.
Cardiff appeared to have found an immediate response but Miller's delicate lob over Kasper Schmeichel from debutant Haris Vuckic's flick-on was ruled out for offside.
It was to be Vuckic's last contribution as he made way for Rudy Gestede at the interval but the Bluebirds had Marshall to thank once more in the 51st minute as he plunged to his right to tip around the post when Lloyd Dyer teed up Nugent.
Beckford continued to probe industriously and found Marshall in his way following a jinking run after the hour.
However, there was nothing the former Norwich keeper could do in the 71st minute when Gallagher capitalised on a foul by Don Cowie on Dyer to plant a sumptuous 25-yard free-kick into the top corner.
Cardiff were offered a lifeline when Schmeichel fumbled Whittingham's corner and Peltier fouled Gestede in the ensuing panic.
Whittingham stroked home from the spot.
Source: DSG