Barcelona’s dream of going a whole La Liga season unbeaten ended in their penultimate game as they were beaten by lowly Levante in a remarkable match.
The hosts moved into a 5-1 lead, with Emmanuel Boateng scoring a hat-trick and Enis Bardhi netting twice.
Barca’s Philippe Coutinho scored a hat-trick of his own and Luis Suarez netted a penalty to set up a tense finale.
But the champions could not find an equaliser as they fell to a first La Liga defeat in 44 games.
Ernesto Valverde, beaten in the league for the first time as Barcelona boss, may regret his decision to rest top scorer Lionel Messi for the trip to 15th-placed Levante.
After coming through their game against Real Madrid unbeaten last weekend, it looked as though history beckoned for Barcelona.
No side have gone an entire Spanish top flight season unbeaten since the 1930s, when there were only 18 games in a season.
But they fell just short in a match that almost defied logic – they had only conceded 24 goals in their opening 36 games.
With the league and cup double already wrapped up, and their Champions League run long over, it makes next Sunday’s final game against Real Sociedad largely irrelevant – except to send off departing captain Andres Iniesta.
How the mayhem unfolded
9 mins: 1-0 – Boateng opens the scoring, via the crossbar, after good play by Jose Luis Morales
13 mins: Almost a second goal as Bardhi hits the post from close range
30 mins: 2-0 – with Thomas Vermaelen off the pitch injured, Boateng goes round goalkeeper Marc-Andre ter Stegen and slams into an empty net after evading defender Nelson Semedo
38 mins: 2-1 – Luis Suarez finds Coutinho, whose 20-yard shot is deflected into the net
46 mins: 3-1 – less than a minute into the second half Bardhi curls a fabulous effort home from the edge of the box
49 mins: 4-1 – Boateng scores the first hat-trick of his career as he smashes home a first-time effort from former Aston Villa defender Antonio Luna’s pass
56 mins: 5-1 – Levante are in dreamland. Barcelona leave too much space at the back and Roger Marti plays the ball to Bardhi, who smashes home
59 mins: 5-2 – Coutinho slams home from close range after Suarez’s shot is blocked, but surely they cannot come back?
64 mins: 5-3 – Coutinho joins Boateng in the hat-trick club with another deflected shot from outside the box – but they still need two more
71 mins: 5-4 – Suarez scores a penalty after Sergio Busquets is fouled, and at this stage a comeback looks likely
90 mins: Levante should make it 6-4 as Busquets’ backpass does not find his keeper – but Ruben Rochina puts it wide from close range
94 mins: The full-time whistle goes to spark huge celebrations at the Estadi Ciutat de Valencia, and probably in Madrid too
Famous win for Levante
Barcelona should have expected a difficult evening at Levante, who have had a dramatic revival under boss Paco Lopez.
When he was promoted from his role as reserve-team boss in March, the club were only one point above the relegation zone.
But they have now won eight of their 10 games since his appointment – to take them 17 points clear of the bottom three.
Lopez said it would be “historic” for Levante, in their first season back in the top flight following promotion, to beat Barcelona and there were big celebrations at the final whistle on a famous night for the club nicknamed the Frogs.
Match ends, Levante 5, Barcelona 4.
Jordi Alba (Barcelona) is shown the yellow card.
Second Half ends, Levante 5, Barcelona 4.
Yerry Mina (Barcelona) is shown the yellow card for a bad foul.
Foul by Yerry Mina (Barcelona).
Giampaolo Pazzini (Levante) wins a free kick in the attacking half.
Gerard Piqué (Barcelona) is shown the yellow card.
Foul by Gerard Piqué (Barcelona).
Rober Pier (Levante) wins a free kick in the defensive half.
Giampaolo Pazzini (Levante) is shown the yellow card.
Jordi Alba (Barcelona) wins a free kick in the attacking half.
Foul by Giampaolo Pazzini (Levante).
Attempt missed. Rubén Rochina (Levante) left footed shot from the centre of the box is close, but misses to the right.
Denis Suárez (Barcelona) is shown the yellow card.
Luis Suárez (Barcelona) is shown the yellow card.
Jefferson Lerma (Levante) is shown the yellow card.
Offside, Levante. Rubén Rochina tries a through ball, but Enis Bardhi is caught offside.
Substitution, Levante. Rubén Rochina replaces José Luis Morales.
Attempt missed. Coutinho (Barcelona) right footed shot from outside the box is too high.
Corner, Barcelona. Conceded by Rober Pier.
Attempt blocked. Sergio Busquets (Barcelona) right footed shot from the right side of the six yard box is blocked. Assisted by Denis Suárez with a cross.
Corner, Barcelona. Conceded by Antonio Luna.
Attempt saved. José Luis Morales (Levante) right footed shot from the centre of the box is saved in the bottom left corner. Assisted by Jefferson Lerma.
Corner, Levante. Conceded by Yerry Mina.
Foul by Jordi Alba (Barcelona).
Coke (Levante) wins a free kick in the defensive half.
Substitution, Levante. Giampaolo Pazzini replaces Emmanuel Boateng because of an injury.
Delay over. They are ready to continue.
Delay in match Emmanuel Boateng (Levante) because of an injury.
Offside, Barcelona. Denis Suárez tries a through ball, but Luis Suárez is caught offside.
Attempt blocked. Denis Suárez (Barcelona) right footed shot from the centre of the box is blocked. Assisted by Paco Alcácer.
Attempt missed. Luis Suárez (Barcelona) header from the centre of the box is too high. Assisted by Denis Suárez with a cross following a set piece situation.
Nélson Semedo (Barcelona) wins a free kick in the attacking half.
Foul by Jefferson Lerma (Levante).
Goal! Levante 5, Barcelona 4. Luis Suárez (Barcelona) converts the penalty with a right footed shot to the high centre of the goal.
José Campaña (Levante) is shown the yellow card.
Penalty Barcelona. Sergio Busquets draws a foul in the penalty area.
Penalty conceded by Emmanuel Boateng (Levante) after a foul in the penalty area.
Corner, Barcelona. Conceded by Sergio Postigo.
Substitution, Levante. Jefferson Lerma replaces Roger Martí.