Alex Dombrandt furthered his case for another chance with England as Harlequins made the play-offs for the first time in seven years.
The No.8 was part of Quins performance that highlighted their pluses and minuses as they scored six tries and conceded four in a helter-skelter game.
The hosts were 32-18 up at the break, 33-32 down after 57 minutes and 39-33 up on the hour and should have put the match to bed.
Harlequins scrum-half Martin Landajo seals victory to secure a play-off place
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.
Tries: Kenningham, Care, Marchant, Northmore, Lewies, Landajo; Cons: Smith (4); Pens: Smith (2)
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.
Tries: McNally, Muir (2), Bayliss; Cons: Priestland (2); Pens: Priestland (3)
But Marcus Smith missed three penalties in seven minutes in the final quarter and Quins, with 4,000 fans back at the Stoop, were made to sweat for their first Premiership semi-final since 2014.
But tries from captain Stephan Lewies, made by Dombrand’s strong run and overhead pass, and replacement scrum-half Martin Landajo’s touchdown at the death sealed it.
John Mitchell England’s defence coach was in the stands, and would have been impressed by Dombrandt, veteran prop Joe Marler and wing Joe Marchant.
But his equivalent at Quins, former Ireland and Munster hooker Jerry Flannery admitted the 80-minute ride to the last four was not a fun experience.
‘It was unenjoyable but I’m accepting that this is the Quins way,’ he said.
‘Things are unconventional here – I’ve never seen a team that can play rugby like Quins when they’re on form. But we have areas of our game to work on.’
Stephan Lewies celebrates after scoring a breakaway try for Quins in the second-half
For Bath this was a fourth league loss in a row and leaves them clinging to eighth spot – and automatic Champions Cup rugby next year.
They showed glimpses with No.8 Taulupe Faletau, centre Max Clark, scrum-half Ben Spencer and full-back Tom de Glanville prominent but have a crunch game against Gloucester in the next round.
Head coach Stuart Hooper said: ‘Ultimately we needed to dictate the game more.
‘As we came into this two out of the last three games was probably what we needed. We go to Gloucester next week which is a huge game.’
Harlequins fly-half Marcus Smith celebrates Saturday’s thrilling victory over Bath