Chelsea finished in the top four despite losing at Aston Villa
Chelsea qualified for next season's Champions League on Sunday despite a 2-1 defeat at Aston Villa as Leicester's loss against Tottenham saved the Blues' top four place in a thrilling end to the Premier League season.
Thomas Tuchel's side were 14 minutes away from missing out on a top-four finish when they trailed at Villa Park while Liverpool and Leicester were both winning.
Bertrand Traore put Villa ahead late in the first half before the former Chelsea winger won a penalty that was converted by Anwar El Ghazi.
Ben Chilwell got one back for Chelsea, but at that stage the Blues were still heading out of the top four.
An own goal from Leicester keeper Kasper Schmeichel was followed by two late Gareth Bale strikes, condemning the Foxes to a 4-2 loss as Chelsea received an unexpected favour from bitter London rivals Tottenham.
That Harry Kane, linked with a close-season move to Chelsea after declaring his desire to quit Tottenham, was also on the scoresheet at the King Power Stadium was an added layer of irony.
Chelsea captain Cesar Azpilicueta was sent off in the final minute after clashing with Jack Grealish.
But the Blues finished one point above fifth-placed Leicester, illustrating the slender margins at play in a pulsating conclusion to the top four race.
It was a huge escape for Chelsea as they enjoyed a significant measure of revenge for their FA Cup final defeat against the Foxes last weekend.
They can now concentrate on Saturday's Champions League final against Manchester City without the extra pressure of knowing they have to win in Porto to qualify for next season's tournament.
But Tuchel has plenty of work to do to get Chelsea in shape for their first Champions League showpiece since 2012 after they were beaten for the third time in their last four games in all competitions.
Adding to Tuchel's problems, Edouard Mendy may be a doubt for the final after Chelsea's keeper was unable to play the second half, having collided with the woodwork in a failed attempt to keep out Traore's goal.
Once again, Timo Werner was unable to provide a spark up front and the Chelsea striker should have done better than head across goal from Azpilicueta's cut-back in the early stages.
Mason Mount deservedly won Chelsea's player of the year award after a superb season.
But the England midfielder wasted a golden opportunity to open the scoring when he blazed over from Azpilicueta's cross.
Chelsea were made to pay for their profligacy when Villa took the lead with a clever corner routine in the 43rd minute.
Traore made a perfectly-timed run to meet Matt Targett's low delivery and, with Chelsea's defenders looking elsewhere, the unmarked winger hit a scuffed shot that looped into the top corner via the crossbar.
Tuchel had said he would not check to see how Liverpool and Leicester were faring until half-time.
By the time Tuchel returned to the dressing room at the break, Liverpool were winning 1-0, while Leicester were level at 1-1, keeping Chelsea in the top four at that point.
But news quickly filtered through that Jamie Vardy had put Leicester ahead early in the second half, leaving Chelsea in peril.
As if that wasn't bad enough, Jorginho conceded a 52nd minute penalty when he caught Traore on the foot.
VAR reviewed the incident but there was no reprieve for shell-shocked Chelsea as El Ghazi stroked home the spot-kick.
Chilwell gave Chelsea a glimmer of hope when the left-back met Christian Pulisic's cross with a close-range finish in the 70th minute.
That set the stage for a remarkable finale as the focus turned to the King Power, where Tottenham's late goal spree sparked jubilant cheers from the Chelsea bench and a relieved smile from Tuchel.