The team known as 'Yellow Submarine' after their canary-coloured shirts had their season wrecked by injuries to key players but now look safe with two games left to play.
Javier Clemente's Gijon, by contrast, are all-but condemned to second division football next term as their valiant effort to avoid the drop ran out of steam at a crucial moment and their captain Alberto Lora was left sitting on the pitch in tears.
Villarreal have 41 points in 16th, one ahead of 17th-placed Rayo Vallecano, who play at Real Mallorca on Wednesday. Gijon are 19th on 34 points, level with Real Zaragoza, who host fifth-placed Levante on Wednesday.
If Rayo avoid defeat in Mallorca Gijon will be down.
Villarreal took the lead when defender Mario sprinted into the area to turn in a Bruno Soriano centre after 19 minutes at the Molinon before Lora levelled with a long-range shot six minutes before half-time.
The home fans' joy was short-lived as Gregory Arnolin brought down Marco Ruben in the penalty area moments after the restart and former Spain midfielder Marcos Senna calmly smashed home the spot-kick.
Villarreal's Hernan Perez was denied by a post in the 53rd minute but made no mistake with a powerful long-range effort two minutes later to extend their lead to 3-1.
Alejandro Galvez gave the home side some hope when he made it 3-2 with five minutes remaining and as the tension mounted and tempers frayed, Gijon coach Clemente was sent from the bench, the first of a slew of late cards.
Villarreal had their backs to the wall but managed to hold out through about seven minutes of disrupted added time as objects rained down on the pitch including a cigarette lighter and a beer can.
Police officers had to intervene to calm down Villarreal pair Carlos Marchena, who had been substituted, and Cesar Sanchez, who was on the bench, on the side of the pitch and the latter was also sent to the stands.
Leaders Real Madrid, who have a seven-point lead over second-placed champions Barcelona, can clinch their first title in four years with a win at Athletic Bilbao on Wednesday.
Jose Mourinho's side will already have sealed the title, however, if Barca lose at home to Malaga in the earlier kick-off.
Third-placed Valencia are level on 55 points with Malaga and host Osasuna on Wednesday as they chase the final automatic Champions League qualifying spot.
Granada moved closer to safety when they won 2-1 at home to Espanyol on Tuesday thanks to a first half double from Nigerian forward Odion Ighalo and are 15th on 42 points, while already-relegated Racing Santander drew 1-1 at mid-table Getafe.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.