Leeds United leapfrogged Burnley with a 2-1 victory at Brentford to earn Premier League safety, with the Clarets losing 2-1 at home to Newcastle United.
Leeds went in front on 56 minutes when Raphinha slotted in a penalty after he had been fouled by David Raya.
A Sergi Canos header restored parity with 12 minutes remaining before the Spaniard was sent off for a second booking.
Jack Harrison secured the victory in the fourth minute of stoppage time with a strike from the edge of the area.
Leeds are the first team to avoid relegation having started the final day in the bottom three since 2011 and finish 17th with 38 points, three clear of Burnley.
Brentford end their debut Premier League season in 13th.
See: Brentford report | Leeds report
Match officials
Referee: Paul Tierney. Assistants: Lee Betts, Neil Davies. Fourth official: Robert Jones. VAR: John Brooks. Assistant VAR: Sian Massey-Ellis.
WHO'S GOING TO BE YOUR
MAN OF THE MATCH?
Vote at Full-time