Leganes have made club history by reaching the quarter-finals of the Copa del Rey for the first time, having shocked Villarreal on Wednesday.
A goal from Nordin Amrabat had given Leganes a slender advantage from the home leg of their last-16 tie.
And when Nabil El Zhar put his side ahead after half an hour at the Estadio de la Ceramica, Leganes were on track to for their maiden last-eight appearance.
Villarreal battled back after the break, though, Dani Raba on target shortly after the interval to set up a grandstand finish.
And, even though Denis Cheryshev scored in the last minute to level the scores on aggregate, Leganes progressed to the quarter-finals on away goals.
Alaves are also in the hat after easing past Formentera, while Atletico Madrid comfortably dispatched of Lleida Esportiu 7-0 on aggregate on Tuesday.