Ashton's first two tries and a Dylan Hartley score put the home side ahead but they were never totally in control at Franklin's Gardens and after Hartley was sin-binned for a cynical kick of the ball, Gloucester fought back.
Nicky Robinson dispatched the resulting penalty and Dave Attwood added to Charlie Sharples' early try to claw the Cherry and Whites back into the game.
But England international Shane Geraghty eased the pressure on Northampton with a late penalty before Bruce Reihana crossed in the final minute, allowing Ashton to touch down for his hat-trick.
Meanwhile, third-placed Saracens closed in on a play-off spot with a 37-18 defeat of Harlequins at Wembley.
England Saxons flanker Andy Saull touched down twice, adding to tries from Schalk Brits, Michael Tagicakibau and Ernst Joubert as the Sarries eased home.
Hooker Chris Brooker handed Quins an early advantage but the visitors couldn't capitalise on their lead and late scores from Ugo Monye and Chris York proved little consolation.
Elsewhere, Wasps edged out Worcester at the Sixways Stadium to move into fourth and Bath completed a routine victory over Sale.
Dominic Waldouck starred for Wasps, touching down twice to add to England flanker Tom Rees' score in a 24-20 victory.
And while Worcester stay rooted to the bottom after defeat, Alex Grove's late try ensured they picked up what could prove a vital bonus point.
Meanwhile, Lee Mears, Olly Barkley, Matt Banahan, Joe Maddock and David Barnes all touched down for Bath as they kept their play-off hopes alive with a 34-15 victory the Recreation Ground.
Victory keeps Bath six points behind Wasps in the final play-off position with a game in hand at home to leaders Northampton on Tuesday.