A try from Michael Smith six minutes from the end condemned the Rhinos to their third League defeat of the season and left Wigan four points clear at the top.
Castleford's best-ever Super League crowd of 8,406 was treated to a feast of entertaining rugby, although that will not be of much consolation to Leeds, who have not won at Wheldon Road since the game switched to summer three years ago.
Castleford - forced to reshuffle their side after the late withdrawals of Barrie-Jon Mather, Richard Gay and David Chapman - were full value for their third home win of the season.
They were the more inventive side, with the forwards Dean Sampson and Smith a real handful for the Leeds defence, creating space for the clever footballing skills of Brad Davis and Danny Orr.
Lacklustre Leeds, playing their first match for three weeks, went in front after seven minutes, when Richie Blackmore, a former Castleford player, grabbed a try following a kick-and-chase and a suspiciously forward pass earlier in the move.
The Tigers pounced for two tries while Leeds loose-forward Marc Glanville was in the sin-bin for holding down Michael Smith.
First Orr sent Flowers through for a 17th-minute try and then Lee Harland and Adrian Vowles produced some bewildering passing to put Jon Wells over.
In first-half injury-time Leeds' Andy Hay off-loaded superbly from a two-man tackle and sent Francis Cummins clear. The League's top try-scorer wrong-footed Jason Flowers and Davis to cross for his 13th touchdown of the campaign.
A fourth goal from as many attempts from Harris edged Leeds 18-16 ahead after three minutes into the second half minutes, but Castleford regained the lead six minutes later.
Orr, who flitted between the stand-off and hooking, wrong-footed Anthony Farrell and slid through for a vital try.
Graham Holroyd crossed for Leeds, but was recalled for a forward pass and the Tigers clinched their success on 74 minutes, when Smith bulldozed his way through for a well-deserved try.
Castleford: Flowers; Wells, Maloney, Vowles, Critchley; Orr, Davis; Sampson, Harland, McKell, Sykes, M Smith, Schick. Substitutes: Ford, P Smith, Tallec, Russell
Leeds: St Hilaire; Sterling, Blackmore, Cummins, Rivett; Harris, Holroyd; Masella, Sheridan, Fleary, Farrell, Hay, Glanville Substitutes: Powell, McDermott, Morley, Mathiou.
Referee: S Cummings (Widnes)Reuse content