Philippe Coutinho hit a hat-trick but could not save Barcelona’s unbeaten season as the Catalans were left stunned by an extraordinary 5-4 defeat to Levante on Sunday. Ernesto Valverde rested Lionel Messi for his team’s penultimate match of the campaign but it was a defensive horror-show that allowed Emmanuel Boateng to score three times and Enis Bardhi twice at the City of Valencia Stadium.

The La Liga and Copa del Rey champions trailed 5-1 after an hour and still came within a whisker of a sensational comeback as Coutinho’s second and third goals, and a Luis Suarez penalty, set up a grandstand finish.

But Levante held on for a thrilling victory, which ends their opponents’ hopes of becoming the first ever club to finish a 38-game La Liga season as invincibles. After drawing at home to Real Madrid last weekend, despite playing the second half with 10 men, and thrashing Villarreal, Barcelona sat just two games away from the historical feat.

It was 1932 when the last side, Real Madrid, went unbeaten in the top-flight but even that was across only 18 matches, in a 10-team division. This was Barcelona’s first league loss since slipping up against Malaga on April 8 last year and while it has minimal impact on the table, Valverde will have questions to answer, not least with regards to leaving out Messi.

“We are angry not to have come through this game and not to have the opportunity to finish unbeaten,” Valverde said. “But in a season some matches go your way and some don’t. I think this result was harsh in all respects but at other times this season, like in Seville, we could also have lost.”

This defensive collapse was reminiscent of their Champions League meltdown against Roma, which has soured an otherwise successful campaign. The unbeaten record was supposed to help atone for the European failure.

“Obviously we wanted to finish the league undefeated,” Sergio Busquets told beIN Sport. “But this does not take away everything we have done otherwise this season - everything we have achieved in league, the run we managed across two seasons - but, it is a shame.”

For Levante, this is their eighth win in 10 matches under new coach Paco Lopez, who took charge with the club in danger of relegation but has overseen a remarkable transformation. They move up to 15th. Paco’s players exploded out of the blocks and pulled ahead in the ninth minute when Boateng nipped in at the near post after Jose Luis Morales’ weaving run down the left.

Bardhi hit the woodwork with a lifted finish over Marc-Andre ter Stegen but Barca failed to heed the warnings and Boateng made it two after half an hour, latching on to Sasa Lukic’s threaded ball through. Coutinho pulled one back with a rasping shot before half-time but three Levante goals in 10 minutes after the interval sent the home fans into delirium. Bardhi’s blistering shot restored the two-goal advantage before Boateng completed his hat-trick as Barca’s defence was ripped apart again on the break.

Another counter just before the hour ended with another crisp Bardhi finish, as Barca were now staring at a four-goal deficit. The game looked dead but Coutinho scored twice in six minutes, the first a close-range finish after Ousmane Dembele’s shot spilled loose, the second an instinctive shot from the edge of the area.

When Boateng brought down Busquets in the area and Suarez drove the penalty down the middle with 20 minutes left, it felt inevitable Barca would find a fifth. But without Messi even to bring on, Levante withstood the late onslaught and should even have scored a sixth only for Ruben Rochina to prode wide after a dreadful backpass by Busquets. It was the final mistake of an error-strewn display.