It kept Bath's hopes of a Heineken Cup berth alive - just - and left the Tigers still needing to secure a home semi-final in the Aviva Premiership play-offs.
The match-winner, with a 73rd-minute try, was captain Francois Louw, who appeared on the shoulder of replacement prop Anthony Perenise to sprint 30 metres to the corner. Louw was also inspirational in the loose, winning turnover ball and leading by example in defence.
The foundations of the victory were laid in the scrum, where Bath had the upper hand for the first time in many seasons.
The hosts' tries came from Simon Taylor, Semesa Rokoduguni and Horacio Agulla, while Tom Croft and Ben Youngs crossed for Leicester and Toby Flood kicked 16 points.
Most of the action took place in the first half, when the old rivals served up 29 points and five tries. Leicester thought they had a third when Matt Smith went over just before half-time, but the try was ruled out by the TMO for an earlier forward pass.
Bath have not been beaten at home in the Premiership since Saracens won 22-0 just before Christmas, but they have won only once away from the Recreation Ground, which is why they have struggled to make top four - or even top six.
Injury-dogged centre Ben Williams was brought in for his first game in three months while Rokoduguni returned from duty with the Army to wear the number 11 shirt. Hooker Rob Webber, lock Dominic Day and flanker Guy Mercer featured among the forwards.
Leicester, needing three points to guarantee a home semi-final in the play-offs, restored Tom Youngs, Geoff Parling and Croft to their pack while Thomas Waldrom started at number 8 and Smith started on the wing.
The Tigers soon showed they were more than ready to run the ball from anywhere and stretched the home defence more than once before a Flood penalty opened the scoring after five minutes.
Stephen Donald missed at the other end but then barged through the first line of defence to create the momentum for Bath's first try. Rob Webber was stopped at the corner but the ball was worked through another phase before Taylor crashed over and Ollie Devoto converted.
Bath were hitting hard on the gain-line but no-one got near Croft when Ben Youngs' pass sent the long-striding flanker clean away between Webber and Davey Wilson before rounding Devoto. Flood's conversion put the visitors 10-7 ahead after 15 minutes.
The lead was short-lived, however, as Rokoduguni picked a Mathew Tait pass out of the air and travelled 40 metres for the try, only for Devoto to miss the relatively easy conversion.
Flood chipped over a penalty to make it 12-13 on 20 minutes and Ben Youngs caught Bath completely cold a few minutes later, tapping a penalty inside his own 22 and racing 80 metres to the line after rounding Devoto. Flood's conversion put Tigers two scores ahead for the first time and they must have thought they had the game won when Smith touched down on 35 minutes. Unfortunately for them, it was ruled out by the TMO when referee Tim Wigglesworth queried a forward pass upfield.
Instead, it was Bath who finished the first half stronger, using their superior scrummage and maul to advance upfield, eventually winning a penalty deep in the Tigers' 22. From the lineout, Donald sent an inch-perfect cross-kick over the left, where Agulla brushed past Tait to score. There was time only for Donald to kick the conversion and make it a one-point game at 19-20.
Flood kicked two penalties early in the second period but Tom Heathcote, coming off the bench for Williams, landed a simple effort on 54 minutes to make the score 22-26.
As more replacements entered the fray, the game lost much of its momentum. Heathcote hit the post with a longer-range attempt. Bath enjoyed all the territory and much of the possession but were desperately searching for a way through or around the Tigers' defence.
Then, seven minutes from time, Perenise came away from a maul - set up by Rokoduguni's catch - and the Samoan prop found Louw with a deft pass. The Springbok flanker raced 30 metres to the corner to score, edging Bath one point ahead. Heathcote's conversion was just wide, but the hosts had done enough.