Aitor Karanka's side will line up against the Spanish outfit at the Riverside Stadium on Saturday, August 2.
Villarreal beat Boro 2-0 at the El Madrigal Stadium in November 2004 on their way to the UEFA Cup semi-finals.
They reached the last four in the Champions League in 2006, the year the Teessiders made it to the UEFA Cup final, only to fall to Sevilla in Eindhoven.
Boro will start their pre-season campaign at Rochdale on July 26 before meeting Hartlepool four days later.
They kick off the new league season at home to Birmingham on August 9.