Scarlets will play in Europe's top tier next season after fighting back from 33-12 down to beat Connacht in their final Pro14 game of the season.
Cardiff Blues beating Edinburgh at the Arms Park at the same time ensured the Scottish team cannot overtake Scarlets, who finished third in Conference B.
On a spectacular night in Llanelli, Scarlets scored six tries to Connacht's five.
Four of the Scarlets tries came after the break in a thrilling fight back.
Connacht went into the game knowing they could not be knocked out of second place in Conference B and having already guaranteed their Heineken Champions Cup spot.
But that did not dim their hunger or resolve as the Irish side battled to the end.
The hosts achieved the win without Wales fly-half Rhys Patchell, who suffered a fresh injury blow in the form of a hamstring problem.
Patchell was due to start at Parc y Scarlets after returning from a four-month concussion absence, having last played for Wales as they lost to Scotland in the Six Nations at the same venue last October.
Flanker Aaron Shingler, recently returned after a long absence caused by an inflammatory illness, crossed wide out early on after a sweeping Scarlets move.
But Connacht took control after the restart and their pressure led to home hooker Marc Jones' sin-binning, soon followed by visiting full-back John Porch going over unopposed.
Scrum-half Kieran Marmion led the attack that ended with number eight Abraham Papali'i powering over as Connacht seized the initiative.
Scarlets were denied a Tom Rogers try after prop Pieter Scholtz was judged to have raised his elbow into the face of Porch in the build-up.
The incident led to Scholtz being sin-binned and Connacht took immediate advantage as centre Sean O'Brien sped clear and took up Porch's return pass to touch down.
Scarlets showed some resistance in response as Steff Evans put Steff Hughes over, Dan Jones added the extras.
The end-to-end action continued as prop Dominic Robertson-McCoy crashed over for Connacht's bonus point try before Marmion finished a superb move to score their fifth try of the opening period.
Wales Six Nations squad centre Johnny Williams' introduction after the break provided some much-needed impetus in the home midfield as his power paved the way for Hughes to touch down under the posts.
Scarlets' fightback continued as lock Sam Lousi stole away at a ruck before putting home nine Dane Blacker over.
Rogers then produced the game's outstanding solo score, leaving Porch in his wake from a standing start.
The hosts absorbed pressure in their own 22 before working their way back upfield for Dan Jones' penalty to put them narrowly ahead.
Scarlets spurned another chance to kick at goal and the gamble paid off as replacement prop Javan Sebastian crashed over from close range to complete a remarkable comeback win for Scarlets.
Scarlets head coach Glenn Delaney told BBC Sport Wales: "That [qualifying for the Champions Cup] was the objective tonight and you probably saw first half we were playing under the weight of that expectation.
"We weren't really free and Connacht were outstanding, they were fast, they played with tempo, they put us under pressure and we conceded cards - even in the act of scoring we conceded a card.
"We had to circle the wagons a bit and focus on the fact that when we had the ball we were scoring, so we just had to maintain possession and we managed to do that in the second half.
"We have a really strong leadership group and... they needed to grasp the nettle and they did, and we can be really proud of them. Our attention to detail at the breakdown was top-notch, probably the best it's been this season."
Scarlets: Tom Rogers; Tom Prydie, Tyler Morgan, Steff Hughes (capt), Steff Evans; Dan Jones, Dane Blacker; Steffan Thomas, Marc Jones, Pieter Scholtz, Lewis Rawlins, Sam Lousi, Aaron Shingler, Jac Morgan, Sione Kalamafoni.
Replacements: Ryan Elias, Kemsley Mathias, Javan Sebastian, Tevita Ratuva, Uzair Cassiem, Will Homer, Angus O'Brien, Johnny Williams.
Connacht: John Porch; Ben O'Donnell, Sean O'Brien, Tom Daly, Alex Wootton; Conor Fitzgerald, Kieran Marmion; Jordan Duggan, Shane Delahunt, Jack Aungier, Niall Murray, Gavin Thornbury, Paul Boyle, Conor Oliver, Abraham Papali'i.
Replacements: Dylan Tierney-Martin, Matthew Burke, Dominic Robertson-McCoy, Oisin Dowling, Sean Masterson, Colm Reilly, Jack Carty, Peter Sullivan.
Referee: Ben Whitehouse (WRU)
Assistant Referees: Ian Davies, Rhys Jones (WRU)
TMO: Jon Mason (WRU).