Moments after Saturday's stinging loss, Xavi said he would not continue next season as the coach of the club he once led as one of the finest midfielders to play the game.
In one of the wildest games of the season, Villarreal led 2-0 before Barcelona roared back with three goals in a 12-minute span to lead 3-2 in the 72nd minute.
But Barcelona's defence again let the side down and new Villarreal arrival Goncalo Guedes levelled on a counterattack in the 84th minute.
Striker Alexander Sorloth, who also set up two goals, scored in stoppage time to put his side ahead, before Jose Morales added to Barcelona's misery.
"As a Barcelona fan, I can't allow this situation to continue, we need a change of course and of dynamics," said Xavi, adding that he made the decision before the loss.
"I would like to announce that on June 30 I will cease being the coach of Barca.''
The midfield great returned to Barcelona as the coach in November 2021, with his only experience a stint in Qatar. He has a contract through the end of next season.
Xavi said he made the decision "several days ago", and although the defeat to Villarreal set the scene for him to announce the decision, he "would have made" it soon enough.
He said he hoped this decision will ease the stress and tension his team are enduring.
The 44-year-old led Barcelona to the Spanish Super Cup title and the Spanish league title last season, the club's first trophies since the exit of Lionel Messi.
But they have struggled this season. Barcelona were crushed by Madrid 4-1 in the Spanish Super Cup in Saudi Arabia two weeks ago, and on Wednesday conceded twice in extra time to lose at Bilbao 4-2.
After a first-half stalemate between the league's top defences, midfielder Javi Munoz put Las Palmas ahead in the 53rd minute from a pass by Sandro Ramírez.
Vinícius Junior levelled in the 66th minute after a nice assist by Eduardo Camavinga.
Tchouameni then went on as a late substitute and powered in a header with six minutes to play to complete the turnaround.
Las Palmas were in eighth place.
Madrid were without top scorer Jude Bellingham, who was serving a one-game suspension for accumulating five yellow cards.
Bellingham and Girona's Artem Dovbyk lead the league with 14 goals each.