Cristian Tello (L) walks past Barcelona's Argentinian forward Lionel Messi. Photograph:( AFP )
Barca last endured defeat on their own patch against Alaves in September 2016.
Barcelona lost at home in La Liga for the first time in more than two years as Real Betis pulled off a stunning 4-3 victory at the Camp Nou on Sunday, despite Lionel Messi scoring twice on his return from injury.
Barca last endured defeat on their own patch against Alaves in September 2016 but, following 42 games unbeaten, their run was halted by a brilliant, counter-attacking display from Betis.
After five games out injured, Messi returned to Barca's starting line-up but his two goals, one from the penalty spot and another deep into injury-time, proved little more than consolations.
Junior Firpo and Joaquin had put Betis two up at the interval before Messi sparked hopes of a comeback from the spot.
Giovani Lo Celso then capitalised on a rare mistake from Marc-Andre ter Stegen only for Barca to come again, Arturo Vidal making it 3-2, having come on as a substitute.
Ivan Rakitic was sent off, however, with nine minutes left and Sergio Canales added a fourth for Betis before Messi poked home in the 92nd minute.
Barca stay top of the table despite the defeat but their lead is down to one point, with Atletico Madrid now breathing down their necks in second, while Espanyol will have a chance to move level on points with the Catalans when they visit Sevilla later on Sunday.
Ernesto Valverde's Barca play Atletico at the Wanda Metropolitano after the international break.
Betis seemed faster, sharper and hungrier while Barcelona's midfield was repeatedly carved open on the break.
It took five passes for the opener, the last a first-time drive from William Carvalho to free Junior down the left. He weaved inside Sergi Roberto and found the net.
Barca had chances. Messi's free-kick found Clement Lenglet on the stretch but his lunging finish was tipped over by Pau Lopez. Ter Stegen denied Cristian Tello with his legs.
Betis were soon pouring onto Barca´s defence again, with Junior's cross evading everyone before finding Lo Celso on the opposite side of the box. His cute cut-back picked out veteran winger Joaquin, who stabbed in Betis' second.
Vidal replaced the jaded Arthur Melo at half-time and shot within a minute of the restart. Messi feathered a through-ball for Sergi but Betis survived the scramble as Luis Suarez lashed wide.
Barca had the momentum and in the 68th minute, they pulled one back, with Jordi Alba pulled down by Tello, and Messi converting the penalty for his eighth league goal of the season.
But the comeback stalled three minutes later as Betis restored their two-goal advantage. Ter Stegen made the error, letting Lo Celso's shot slip through his fingers and into the far corner.
Barca were not done yet. 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.
First, Rakitic was sent off, a second yellow card for a late challenge on Lo Celso, and then Canales pushed in Betis' fourth from Junior's cross.
Messi added his second in injury-time, tapping a Vidal pass over the line. The video assistant referee deemed Messi onside but there was no more late drama as Betis held on for a shock victory.