Harlequins secured a Premiership play-off place with a bonus-point victory against Bath, who made their hosts graft hard in a high-scoring contest.
Quins picked up the extra point they needed with four first-half scores in a rip-roaring, sun-bathed encounter at The Stoop, establishing a 32-18 lead.
Bath came out fighting in the second half, taking advantage of Joe Marchant's yellow card to edge ahead.
But Quins, back to a full complement, stormed back to seal a top-four finish.
It is the first time in seven years Quins have made the play-offs, and they will relish the prospect of trying to reach the final - over the road at Twickenham - on 26 June.
They may need to do it the hard way, with no away side winning a Premiership semi-final since 2015, although Quins still have an outside chance of finishing second with two games of the regular season left.
In attack they have the variety to trouble teams, as borne out by the tries.
Jack Kenningham scored on the back of repeated close-range surges, Marchant and Danny Care both profited from errors for their scores, while Marcus Smith's creativity paved the way for Luke Northmore's effort.
Bath's hopes of a top-eight finish and a place in the elite European Champions Cup next season were dented by this loss, although they did claim a losing bonus point as reward for their contribution.
Winger Will Muir used his bulk to good effort for his two scores, while the footwork of lock Josh McNally took him over for a superb solo effort.
Ben Spencer knocked on with the line beckoning after Bath had ground their way in front at 33-32, a moment which might have changed their fortunes.
With 4,000 fans back at the famous old ground, the sides served up some sumptuous rugby, punctuated by some poor defence which would have had their coaches cringing with embarrassment.
Too often, Quins showed a soft core when Bath bullied through the middle, while Bath's restarts offered Quins fresh ball on the back of tries scored.
Among the palpitation-prompting errors and thumping contacts were some sublime moments of subtlety, such as Smith's double-pump to release Alex Dombrandt for Stephan Lewies' score, while debutant Max Ojomoh produced a superb 20-metre pass to create Josh Bayliss' touchdown.
Fly-half Smith's off-day with the boot made the finish a slightly frantic one, but Quins had enough in the tank to ensure they would be involved in the end-of-season mix-up.
Harlequins: Green; Earle, Northmore, Lang, Marchant; Smith, Care; Marler, Baldwin, Louw, Symons, Lewies (capt), Lawday, Kenningham, Dombrandt.
Replacements: Gray, Garcia Botta, Collier, Lamb, White, Landajo, Tapuai, Morris.
Bath: De Glanville; Cokanasiga, Clark, Ojomoh, Muir; Priestland, B Spencer; Bhatti, Du Toit, Stuart, McNally, Ewels (capt), Reid, Underhill, Faletau.
Replacements: Doughty, Schoeman, Thomas, W Spencer, Bayliss, Chudley, Bailey, Joseph.
Referee: Tom Foley.