It looked as though the title-chasers would cruise to a routine victory over their struggling hosts when they scored twice in the space of four first-half minutes, but it proved to be anything but straightforward as the two sides played out a game-of-the-year contender.
Malcom created the first for Philippe Coutinho before getting his own name on the scoresheet in a thrilling first half which then saw Samuel Chukwueze pull a goal back midway through the opening 45 minutes.
Karl Ekambi levelled things up five minutes after the interval before goals from Vicente Iborra and Carlos Bacca appeared to have sealed a three crucial points for the relegation-threatened Yellow Submarine.
However, a red card for Alvaro Gonzalez forced Villarreal to finish the game with 10 men, and Lionel Messi - who started the game on the bench - handed Barcelona late hope with another stunning free kick to add to his collection.
Messi then provided the corner which led to Luis Suarez's dramatic equaliser in the final minute of stoppage time, with the Uruguayan lashing a brilliant half-volley past the keeper to cap a match which had everything.
The result ultimately sees Barcelona's lead cut by two points after Atletico Madrid beat Girona earlier in the day, but it is a draw which will feel like a win as they bid to defend their title.
Barcelona boss Ernesto Valverde decided to rest the likes of Messi, Gerard Pique and Ivan Rakitic, but that did not prevent an action-packed contest and the tone was set after just three minutes when Suarez drew the first save from a tight angle.
It was Marc-Andre ter Stegen who was the busier of the two keepers in an end-to-end opening 10 minutes, though, and the German made his first important save to tip Iborra's header over the crossbar.
The resulting corner found Alfonso Pedraza in space only for the midfielder to miss his volley, and the hosts threatened again moments later when the dangerous Chukwueze showed great pace to storm past Samuel Umtiti before being denied by another good Ter Stegen save.
Sergio Asenjo was forced to backpedal furiously seconds later when Suarez tried to catch him out with a shot from the halfway line, but Villarreal were soon back on the attack themselves and Ekambi curled an effort just high and wide of the target as the hosts pushed for an opener.
If Villarreal's attacking performance in the first half belied their lowly league position, their defensive display showed exactly why they have struggled so much this season and Barcelona soon began to cut them open at will.
The first goal nonetheless came against the run of play in the 12th minute when Sergi Roberto released Malcom down the right flank and the young Brazilian slid the ball inside for his compatriot Coutinho, who was left with a simple sliding finish into the empty net.
VAR led to a delay awarding the goal, but Malcom was eventually ruled onside and the creator became the goalscorer moments later as Barcelona made it a quickfire double to take complete control of the contest.
Arturo Vidal's cross into the box was just too high for Suarez, but Malcom was coming in at the back post to send a looping header into the opposite corner for his first ever La Liga goal.
The two-goal deficit was harsh on Villarreal at that stage, but they were fortunate not to fall significantly further behind during Barcelona's spell on top and Coutinho should have made it three goals in the space of six minutes when he dinked a finish against the post after cutting the defence open on the break in tandem with Suarez.
The visitors bisected the Villarreal defence again shortly afterwards when Malcom was sent through down the left this time and played a low ball into the box which Umtiti could only put wide when he should have done better.
Coutinho then stung the palms of Asenjo with a long-range effort having again been afforded too much room, but Villarreal dragged themselves back into the match out of nothing midway through the first half.
Chukwueze - a thorn in the side of Umtiti and Clement Lenglet all night - latched on to Santi Cazorla's pass before beating Jordi Alba and seeing his initial strike hit the post, only to keep his composure from the rebound to slot a second attempt into the bottom corner.
That goal changed the game as Villarreal suddenly began to play with confidence again, while Barcelona's defence was breached on numerous occasions in the absence of Pique.
One such occasion came five minutes before half time when Chukwueze pounced on a loose ball inside the area while the Barcelona defence went to sleep, but Ter Stegen was once again alert to bail his side out.
Suarez drew one final save from the keeper with a long-range free kick before half time, but the visitors were second best after Villarreal's first goal and that continued beyond the interval.
The equaliser came just five minutes after the restart when Barcelona's defence was once again undone by pace, with Chukwueze playing the ball down the line for Ekambi. The striker had Iborra bursting into space in the middle, but instead managed to beat Ter Stegen at the near post from a seemingly impossible angle after the Barcelona keeper had wrongly anticipated a cross.
It was a day to forget for Barcelona defensively both from open play and from set pieces, with Cazorla's quality delivery from corners causing them repeated problems and Alvaro twice missed the target from such chances when he should have done better.
Valverde turned to Messi off the bench in an attempt to swing the game back in Barcelona's favour, but just seconds later Villarreal took the lead when Iborra latched on to a through-ball from Manu Morlanes before clipping his finish past Ter Stegen - another goal which accentuated the chasm between Barca's two French centre-backs.
Messi's first impact came with a clipped pass into the path of Malcom which led to a shooting chance for Suarez, but it was the hosts who continued to look most like scoring and it took a brilliant reaction save from Ter Stegen to turn Chukwueze's deflected shot against the crossbar after 68 minutes.
Another fine team move from the irrepressible hosts saw Ekambi draw another low save from Ter Stegen shortly afterwards, whereas at the other end Malcom turned down a pass inside to Messi to instead slam a shot into the side-netting and waste a good opportunity for the visitors.
It looked as though Villarreal might have finally wrapped up a famous comeback victory when they added a fourth with 10 minutes remaining, Cazorla again taking advantage of the oceans of space in the Barcelona defence to thread a ball through the middle for Carlos Bacca, who rounded the keeper and slid the ball into an empty net.
The hosts' hopes of seeing out the game were hit by Alvaro receiving a second yellow card with four minutes of normal time remaining, though, clattering into the back of Suarez to be issued his marching orders.
Even against 10 men, though, Barcelona needed the genius of Messi to get them out of jail, and the Argentine gave his side a glimmer of hope with a 90th-minute free kick which was placed to perfection as it clattered in off the post - his sixth direct free kick goal of the season and the third successive club game in which he has scored from one.
Time was still on Villarreal's side and Messi fired a desperate long-range strike over the bar in stoppage time before Suarez stepped up with his own moment of quality to cap off a remarkable contest in the final action of the match.
Villarreal could not clear Messi's corner properly and the ball fell to Suarez, who lashed a piledriver of a left-footed half-volley through the crowd and slamming into the back of the net, sparking wild scenes of celebration from the visitors.
The result leaves Barcelona with an eight-point lead over Atletico ahead of this weekend's meeting between the two sides, while Villarreal move two points clear of the relegation zone and could drop into the bottom three if results go against them on Wednesday night.
VILLARREAL (3-4-2-1): Asenjo; Alvaro, Funes Mori, Ruiz; Mario, Morlanes (Caseres 63'), Cazorla, Pedraza; Chukwueze (Bonera 88'), Iborra; Ekambi (Bacca 74')
BARCELONA (4-3-3): Ter Stegen; Roberto, Umtiti, Lenglet, Alba; Vidal, Busquets (Rakitic 73'), Arthur (Alena 73'); Malcom, Suarez, Coutinho (Messi 61')body check tags ::