Bayern entered the match after a surprise 1-0 defeat to Aston Villa on matchday 2, and while they showed promise early on, the night belonged to the Catalans.
Raphinha opened the scoring by latching onto a through ball, rounding goalkeeper Manuel Neuer, and slotting home.
Harry Kane thought he had equalized in the 10th minute, but his effort was disallowed for offside. Kane eventually made it 1-1 with a volley in the 18th minute after a Serge Gnabry cross.
Barcelona regained the lead in the 36th minute through former Bayern star Robert Lewandowski, who finished into an empty net after a defensive mix-up. Just before halftime, Raphinha struck again with a curling shot after a brilliant run down the right flank.
In the second half, Raphinha sealed his hat-trick with a clinical finish in the 56th minute, racing onto another long ball and driving a low shot past Neuer.
After three games, Barcelona sit in 10th place on six points, while Bayern are further down in 23rd spot.