
Edvardsen buried a cutback cross from flying fullback Anton Gaael in the 90th minute to see the Dutch giants, who had lost their first five group games, come from behind to win a second successive tie.
This means they still have a chance of finishing in the top 24 with a home game to come against Olympiacos of Greece next week.
Villarreal are eliminated, stuck second from bottom with a single point as poor form in Europe contrasts with their third place in La Liga.
Tani Oluwaseyi had given the hosts a 49th-minute lead with a superb volley but Oscar Gloukh’s free kick saw Ajax equalise in the 61st minute before they snatched a much-needed three points.