Lionel Messi scored twice on his return to action following a broken arm but could not stop Barcelona suffering a surprise defeat at home to Real Betis.
Messi broke his arm against Sevilla on Oct. 20 but made a quick recovery to take his place in Barcelona's starting XI at Camp Nou.
Junior Firpo struck for Betis on 21 minutes before Joaquin Sanchez doubled the lead before the break. Messi reduced the deficit on 67 minutes with a penalty but Giovani Lo Celso made it 3-1 soon after. Substitute Arturo Vidal gave Barcelona hope when he made it 3-2 11 minutes from time before Ivan Rakitic was sent off for a second booking and Sergio Canales made the game safe.
Messi added his second in injury time following a VAR referral but it wasn't enough to stop Barcelona from stumbling to defeat.
"We will enjoy this victory and the joy and satisfaction we have given to Betis fans who follow their team every day, winning here and scoring four goals is something you will never forget," said Betis coach Quique Setien.
"When you come here, you always expect to suffer but we knew if we showed character and overcame the stress we could play well and have the ball, and Barca are a team that suffers without the ball and struggles to get it back."
Betis should have opened the scoring on nine minutes when Joaquin found space in the area but he skied his effort from close range.
But the visitors did not have to wait much longer to go ahead, with Firpo scoring a fine opener. William Carvalho's superb pass found Firpo, who unleashed a fine right-footed drive past Marc-Andre ter Stegen.
Joaquin, 37, then added a second for Barcelona just over 10 minutes later after Betis poured forward in attack. Firpo's pull back evaded everyone before Joaquin was on hand to finish off.
Arthur Melo was replaced by Vidal for the second half and Barcelona started positively, with Messi going close before Clement Lenglet headed over. Just before the hour mark, Messi again went close for the home side, who desperately searched for a way back into the game.
Real Betis hit the post before Cristian Tello fouled Jordi Alba in the box and Messi made no mistake from the penalty spot. Betis, though, hit back straight away with their third through Lo Celso.
Lo Celso blasted a shot towards goal and it seemed routine enough for Ter Stegen but the ball squirmed through his grasp and into the back of the net to deepen Barcelona's misery.
Vidal pulled one back but Rakitic then saw red to leave Barcelona with too much to do to get back into the game. Canales then made sure of the victory by notching Betis' fourth six minutes from time.
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.
"The problem was that we did not play well, we did not control the game and we kept on making mistakes which is why we were behind at half time," said Barca coach Ernesto Valverde.
"In the second half every time we scored and got back in the game they struck back immediately."
It was the Catalans' first defeat at home since they were beaten 2-1 by Alaves in September 2016 and the first time they have conceded four goals in a league game since they were beaten 4-2 by Deportivo La Coruna in April 2003.