Only a few months after lifting the Spanish title, Barcelona coach Xavi Hernandez dramatically announced he would walk away from the club at the end of the season.

The 44-year-old, who excelled in Barcelona's midfield during 17 years as a player, described the job as his "dream" in the years before he was appointed in November 2021.

After a 5-3 collapse against Villarreal on Saturday which left the champions 10 points adrift of league leaders Real Madrid, Xavi said coaching Barcelona was a "cruel and unpleasant" experience.

Real Madrid thrashed Barcelona 4-1 earlier in January to win the Spanish Super Cup and Athletic Bilbao hammered the Catalans 4-2 on Wednesday to eliminate them from the Copa del Rey, paving the way for Xavi's decision. 

Xavi took over in one of the toughest moments of Barcelona's history, a few months after their greatest ever player Lionel Messi left, with the club in dire economic straits.

The coach, who won 25 trophies with Barcelona as a player in 767 appearances, led the team from ninth in the table to second in his first season at the helm, securing Champions League qualification.

Xavi followed that by winning the Spanish Super Cup in January 2023 and then Barcelona's first league title since 2019, with his project gathering speed.

Humiliating consecutive group stage Champions League exits blotted his copybook, but Barca appeared to be improving after largely dismal spells under Quique Setien and Ronald Koeman.

Despite winning La Liga, some media and supporters grumbled that the team was not playing good football.

Xavi, the symbol of Barcelona's possession game as a player under Pep Guardiola, was expected by supporters to deliver that kind of dominant football -- and he insisted it was his aim.

Yet Barcelona won the title on the basis of their superb defence, conceding just 20 times in 38 La Liga matches. This season they have already let in 29 in 21 games.

The collapse of that defensive strength and worsening performances have led Xavi to walk away, he says to change a "negative dynamic" around the team he loves.

Defensive woes

Several factors have played into Barcelona's struggles at the back this season.

Perhaps stung by criticism of his team's dutiful but drab performances, Xavi brought in full-back Joao Cancelo on loan to play a more attacking brand of football.

Last season the defence featured three centre-backs -- Jules Kounde, playing on the right, Ronald Araujo and Andreas Christensen, with Alejandro Balde at left-back. 

This season Xavi started with Balde and Cancelo and two centre-backs, foregoing stability for attacking thrust on the flanks.

Kounde had also tired of playing at right-back, often telling media he would prefer to play in the middle.

Veteran holding midfielder Sergio Busquets departed at the end of last season, leaving a yawning chasm in the pivot role he made his own for 18 years.

"We have to find that player if we want to compete well next season -- it's the key," said Xavi in May.

However Barcelona could not afford their prime targets and settled for former La Masia player Oriol Romeu, signed cheaply from neighbours Girona.

Romeu struggled and Xavi dropped him, playing with an even more attacking line-up without a natural defensive midfielder.

Tenacious box-to-box player Gavi suffered a cruciate ligament injury in November, further damaging the team's capacity in that regard.

"We are playing with Pedri, (Ilkay) Gundogan and Frenkie (de Jong)," said Xavi last week.

"Before we had Busquets and Gavi ... Busquets steals 20 to 30 balls for you, Gavi steals 20 to 30 balls."

Another injury to first-choice goalkeeper Marc-Andre ter Stegen, vital last season, has contributed to the sharp increase in goals conceded.

Inaki Pena, standing in for the German, shipped 31 goals in 15 games.

Barcelona have let in three goals this season within the first minute of matches, with concentration lacking.

In attack the team have struggled too -- Joao Felix has not convinced, while Robert Lewandowski, 35, looks his age.

Despite Xavi's intentions, the team's performances have only sparkled on a handful of occasions across his two-year stint.

"We're lacking in both boxes," Xavi has said on various occasions, as excuses piled up along with points dropped.

Xavi left as a hero after winning the treble in his final season as a player in 2015.

Barring a miracle in La Liga or an unlikely Champions League charge, his departure as coach will be far less triumphant.