Goals from Union's Grischa Proemel, Christopher Trimmel and Sheraldo Becker stunned the home crowd, who had been hoping to celebrate their team's first ever qualification for the Champions League after an otherwise remarkable season.
Lucas Hoeler pulled a goal back in the 59th, but despite dominating for the last half hour Freiburg could not find any more goals.
The visitors then struck again in the last minute through Andras Schaefer to secure European football for next season, but they will have to wait and see if it is in the Europa League or Europa Conference league.
Leverkusen made sure of Champions League football next season the hard way, twice coming from a goal down to beat Hoffenheim 4-2 with two goals from forward Patrik Schick.
Moussa Diaby and Lucas Alario were also on target as Leverkusen broke the club's goal record for a Bundesliga season with their 78 goals scored. They are in third place on 61 points.
Freiburg are fourth on 55, with RB Leipzig, on 54, in action against Augsburg on Sunday, and Union also on 54 in sixth and on course for a Europa League spot in their best ever season.
Cologne will also have to wait until the final matchday to find out what European competition they will be playing in after nailing down a top-seven spot despite their 1-0 loss to VfL Wolfsburg.