The Whites needed to better Burnley's result at home to Newcastle United on the final day and they achieved exactly that, as a 2-1 defeat for the Clarets helped Jesse Marsch's men climb to safety.
After a goalless first half, which saw Leeds fail to register a single shot on target, the visitors broke the deadlock when Raphinha converted from the penalty spot in the 56th minute, after drawing a blatant foul from Brentford goalkeeper David Raya.
However, Leeds managed to snatch all three points in the 94th minute when Josh Dasilva cleared a Raphinha cross straight into the path of Jack Harrison, who rifled a strike into the bottom left-corner.
Harrison's late strike was the fourth winning goal score by Leeds beyond the 90th minute in this season's Premier League, more than any other team in the division.
Leeds can now prepare for their third season in the Premier League, while Burnley's five-year spell in the top flight is over.