Raphinha struck just over a minute from kickoff before Harry Kane brought scores level on 18 minutes with a volley.
Former Bayern striker Robert Lewandowski restored Barca's lead on 36 minutes after an error in the visitors' defence.
Raphinha then took over, scoring twice more to complete his hat-trick before halftime.
The second-half saw both teams tighten up, with the scoreline remaining the same as Barca ranout 4-1 winners.
The result was Barca's first win against Bayern in over a decade.
The Blaugrana are now ninth in the Champions League standings on six points from three games, with Bayern langushing 23rd on three points after a second consecutive defeat.
