The Yellow Submarines went into the tie as underdogs following their 1-1 draw with Panathinaikos at El Madrigal.
However, goals from Ariel Ibagaza (49) and Joseba Llorente (70) won the tie for Manuel Pellegrini's men as Vangelis Mantzios scored the hosts' goal on 55 minutes.
Despite playing away from home, Villareal looked keen on taking the attacking initiative.
The Spaniards had an Ibagaza goal disallowed in the 36th minute after the referee judged that Giuseppe Rossi fouled Lukas Vyntra before the ball reached Ibagaza.
The Argentine playmaker made up for it four minutes after the restart with a shot from outside the box after being fed by Joan Capdevilla.
The hosts equalized when Mantzios raised his jump higher than the Villareal defence to head Giorgos Karagounis' corner past Diego Lopez.
Villareal scored the winning goal after Ibagaza's pass was finished off by a volley from substitute striker Llorente twenty minutes from time.