The home side opened the scoring after six minutes with a try from Michael Shenton, but Widnes responded through Kevin Brown to leave the scores level in a close opening 12 minutes.
The latter stages of the first period remained equally as close, with Widnes leading 12-10 at the break courtesy of a try from Stefan Marsh.
A goal from Scott Wheeldon opened the scoring for Castleford in the second period, before a Luke Dorn try added to Castleford's lead two minutes later.
Marc Sneyd was in on the act with two goals moments later as the home side took control of proceedings.
Dorn's second try of the match moved Castleford onto 34 points after 48 minutes, but Widnes moved onto 18 points just before the 70-minute mark with a try from Cameron Phelps and a goal from Danny Tickle.
Tom Gilmore then registered a try for Widnes, who moved onto 22 points, but it was too little too late as the home side secured the win by 12 points.