Villarreal gave their Champions League hopes a much-needed shot in the arm although they required a controversial winning goal from Ruben Cani to beat struggling Recreativo Huelva 2-1.
Recre were left fuming after appearing to clear Cani`s 67th-minute chip before it crossed the line but, after a delay, the goal was given and Villarreal could celebrate a vital win.
The visitors had earlier threatened an upset when Javier Camunas gave them a first-minute lead, but Joseba Llorente levelled before the break.
The Yellow Submarine had taken just four points from their previous five games to slip out of the top four, but this result gets them back in the hunt for a Champions League spot at the end of the season.
For Recre, though, the defeat was both heartbreaking and potentially costly, as they fell to second-bottom after suffering their sixth loss in seven matches.
It was looking good for Recre early on at El Madrigal as they needed just 56 seconds to open the scoring through Camunas - having gone 312 minutes without managing a goal previously.
Villarreal defender Gonzalo Rodriguez was unable to clear the ball and Camunas nipped to steal possession and, despite losing his balance, managed to lash a shot into the roof of the net for his ninth goal of the season.
The visitors then more than held their own against out-of-sorts Villarreal, although neither side looked like scoring until the hosts drew level five minutes before half-time thanks to a brilliant finish from Llorente.
Cani`s fine ball over the top put Llorente in behind the Recre defence, and the former Real Valladolid striker took one touch before lobbing Asier Riesgo from the edge of the box with an effort that went in off the underside of the bar.
That gave Villarreal the boost they needed and they pushed forward for a second goal before the break, and should really have got it in the 44th minute.
However, Giuseppe Rossi was unable to get a firm connection on the ball with the goal gaping, and the sliding Iago Bouzon was able to block the effort on the line.
That was a disappointing end to the half for a Recre side who had moved the ball around well, but the Andalusian outfit picked themselves up for the second half and had a great chance to re-take the lead in the 64th minute.
Goalscorer Camunas picked out unmarked team-mate Javi Fuego at the far post but the 25-year-old could not get his header on target and the chance was lost.
That proved to be a costly miss, as just two minutes later Cani scored what would turn out to be the winning goal.
The number 10 did superbly to skip past his marker in the area before sending a deft chip over Riesgo.
The goal was not immediately given, though, the Recre defence having got back to clear the ball, and play continued for a period with Villarreal claiming it had gone in and Recre attempting a breakaway.
The goal was eventually awarded, much to Recre`s fury, and television replays suggested the visiting side had every right to be upset.
It was a controversial way to win the match, although Villarreal will argue they were also the victims of a poor decision three minutes later when Nihat Kahveci curled home a brilliant free-kick only for it to be ruled out for an offside against Diego Godin.
Recre tried to hit back in the closing minutes but aside from a Nasief Morris free-kick that struck the side-netting, they could not get back on level terms.