The 19-year-old England Under-20 cap, on as a replacement, calmly slotted the crucial three-pointer with 10 minutes to play of a fiercely-contested West Country derby after Matt Banahan had been guilty of not rolling away.
Gloucester had led 11-5 at the break thanks to a try from prop Nick Wood and two Freddie Burns penalties.
Bath had opened the scoring after wing Tom Biggs showed good footballing skills to touch down and a penalty apiece from centre Olly Barkley and fly-half Tom Heathcote levelled matters entering the final quarter, only for Mills to strike the clinching kick.
The win dents Bath's hopes of Heineken Cup qualification but Gloucester's win leaves them well-placed to launch a late surge for a place in the Aviva Premiership semi-finals.
Clashes between the two rivals have always been feisty affairs and this meeting proved no different as both sides lost a man to the sin bin after just two minutes.
A clash between second rows Jim Hamilton and Ryan Caldwell escalated into a confrontation involving all 30 players. The two locks were handed yellow cards by referee Wayne Barnes and continued to exchange words as they headed to the touchline.
Bath had the better of the territory in the early going and they made the most of it as Biggs claimed the opening try after 10 minutes.
Gloucester were penalised for an early lift at a line-out on their 10-yard line, Bath took the free-kick quickly and it was the unlikely figure of hooker Lee Mears who put a cute grubber in behind Charlie Sharples for Biggs to kick ahead and dot down.
But Gloucester hit back with a well-crafted try eight minutes later.
Burns made a half-break through three Bath forwards defending against him and fed centre Eliota Fuimaomo-Sapolu. The Samoan put Mike Tindall clear, the England centre did not have the pace to make it the ball was worked back left where a depleted home defence was punished as James Simpson-Daniel's long pass put prop Wood in at the corner despite Olly Woodburn's desperate covering tackle.
Fresh from his try Wood then used his more renowned scrummaging abilities to force a penalty out of Anthony Perenise, but Burns somehow contrived to miss from in front of the posts.
But the fly-half did give Gloucester a deserved lead with his second penalty attempt, although it came after flanker Akapusi Qera blew a certain try by ignoring a two-man overlap and then dropping the ball as he reached for the line having been hauled down by Banahan.
Barkley then missed a penalty sitter of his own and while Burns was himself off target moments later he did reward another concerted period of Gloucester pressure by closing the half with a long-range three-pointer after Biggs had felled flanker Tom Savage with a high shot.
Gloucester started the second half with an impressive scrum and driving maul, while the combination of full-back Jonny May and wing Simpson-Daniel looked dangerous on the counter.
Bath hit back as a lovely rehearsed move sent Woodburn scything through the Cherry and Whites' defence. The hosts battered away at the line and were repelled by illegal means, allowing Barkley to trim the gap with his first successful penalty before Heathcote tied the scores with a three-pointer of his own moments later.
But that good work was undone when Banahan was penalised for not rolling away in the tackle and Mills punished the indiscretion.
Bath had one last chance to snatch victory but a knock-on at the crucial line-out gave Gloucester the win.
Gilbert has released a new line of rugby cleats. The Gilbert Virtuo 8S is part of the exciting new product. Check it out.
The Barbarians are one of the top invitational rugby sides with a long history and classic rugby jersey.
The Nike Tiempo is a solid rugby cleat and one of few styles still made from full-grain natural leather.
The Lions get ready for their matches with this green training jersey. It's what the players wear. Get in the Gear!
A cool looking all black rugby cleat with the high performance adidas is known for. Get in the Gear!
Wear the crest of the British and Irish Lions on your t-shirt. A great look for the summer.
The Lions are ready to get their Australia tour underway. They arrive in Perth on Monday.
The New Zealand All Blacks training jersey for 2013/14. Get in the Gear!
The USA Rugby Pro Alternate rugby jersey is perfect for any fan of the Eagles. Get yours to wear during the summer Test matches.
The NEW All Blacks 2013/14 jersey has arrived at World Rugby Shop. Dare to wear the colors of the All Blacks.