Ernesto Valverde's men started sluggishly and were punished after 20 minutes when Junior scored his second league goal of the season before veteran winger Joaquin doubled their advantage 11 minutes before the interval.
A chaotic display at the back from Barca allowed Junior, Joaquin, Giovani Lo Celso and Sergio Canales to all get on the scoresheet - the first time they have conceded four at home since a 4-2 defeat to Deportivo La Coruna in April 2003.
Barcelona's second league loss of the season left it one point ahead of Atletico Madrid, which it visits next round after an global break.
The loss ended an unbeaten run of 42 consecutive home games for Barcelona in the league dating back to a 2-1 defeat to Alaves on September 10, 2016.
There was still time for Messi to grab his second of the game deep into stoppage time but Betis clung on to record a memorable win. "Teams can't come here and bang in four goals against us", he said.
The Argentinian came close to scoring in the opening minute but failed to properly connect with the ball and Betis quickly asserted themselves, seriously challenging Barcelona for ball possession, the rarest of sights for opponents at the Nou Camp.
- Setien is the only away manager to win at the Santiago Bernabeu and Camp Nou in LaLiga in the last 10 seasons.
"It's not a punishment, everyone can take it how they like", the coach explained. William Carvalho's superb pass found Firpo, who unleashed a fine right-footed drive past Marc-Andre ter Stegen. His cute cut-back picked out Joaquin, who stabbed in Betis' second.
Vidal replaced the jaded Arthur Melo at half-time and shot within a minute of the restart.
Moments after firing agonisingly wide of Ter Stegen's post, Tello pulled Jordi Alba's shirt in the area and Messi slammed home the resulting spot-kick. Two substitutes combined for a second, Munir El Haddadi laying on Vidal to make it 3-2 but no sooner had the recovery began again, it was halted.
In a breathless finish the impressive Vidal made it 3-2 on 79 minutes, but Rakitic was sent off for a second bookable offence two minutes later and Canales quickly restored his side's two-goal cushion from Junior's cross.