Scott Linton scored twice as Cowdenbeath completed back-to-back league victories to put a dent in Dunfermline's promotion hopes.
Lewis Milne put the home side ahead in the 33rd minute with a curling effort from the edge of the area which nestled into the bottom corner.
The Pars levelled with 20 minutes left as Ryan Wallace's free-kick was headed in by Andrew Dowie from close range.
Andrew Kirk then put the visitors ahead a minute later as he received Craig Dargo's cut-back and rifled in from 18 yards.
But four minutes later Linton's 25-yard free-kick found the net before Kane Hemmings put Cowdenbeath ahead with a low drive from just inside the box with nine minutes remaining.
Linton secured the win in the 88th minute as he clinically shot past Paul Gallacher from the edge of the penalty area.
Cowdenbeath: Flynn, Brett, Armstrong, O'Brien, Adamson, Stevenson (Miller 78), Milne, Robertson, Linton, Coult (Stewart 61), Hemmings. Subs Not Used: Wight, McKenzie, Mbu.
Booked: Coult, Adamson. Goals: Milne 33, Linton 75, Hemmings 81, Linton 88.
Dunfermline: Gallacher, Millen, Dowie, Morris, McMillan, Falkingham, Kane (Whittle 64), Byrne (Thomson 28), Wallace, Kirk, Cardle (Dargo 59). Subs Not Used: Hrivnak, Potter.
Goals: Dowie 70, Kirk 71.
Ref: David Somers