Marcelino Garcia Toral's side started the day three points behind Sociedad, but goals from Giovani dos Santos and Ikechukwu Uche saw them pip their opponents to sixth place in the table thanks to a better head-to-head record.
Dos Santos opened the scoring on 26 minutes when his low effort from outside of the penalty area went in off the post.
Sociedad had a glorious chance to equalise in first-half stoppage time, but Markel Bergara could only flash his shot inches wide after working himself some space in the box.
Villarreal punished those missed opportunities with 20 minutes left on the clock as Uche converted from close range following Dos Santos's assist.
Carlos Vela netted his 17th goal of the season to reduce the deficit for Sociedad deep in injury time, though it was not enough to stop the visitors claiming the points.