Trailing after a 3-0 loss at Barcelona last week, Bayern went ahead when Medhi Benatia scored on a header off a corner kick in the seventh minute.
Neymar scored four minutes later, and the away goal meant Bayern needed a four-goal victory to advance.
Bayern's Mario Goetze (from l. to r.), Javi Martinez, Sebastian Rode and Juan Bernat react after failing to advance to the Champions League final.
Neymar’s second goal put Barcelona ahead 2-1 in the 29th, and Bayern got goals from Robert Lewandowski in the 59th and Thomas Mueller in the 74th.
Bayern coach Pep Guardiola, who coached Barcelona to 14 titles from 2008-12, exchanged an extended hug with current Blaugrana coach Luis Enrique after the final whistle.