The Dutch winger curled a finish into the top corner from the edge of the box with 10 minutes remaining as Villa claimed their first win in four matches.
Ollie Watkins’ 13th Premier League goal of the season had earlier put Dean Smith’s team ahead, though they were quickly pegged back by Dominic Calvert-Lewin.
Villa twice hit the woodwork while Everton keeper Jordan Pickford saved from Watkins and Bertrand Traore but El Ghazi’s late strike ensured the visitors would not be denied.
The goal was El Ghazi’s eighth in the league this season and came at the same end of Goodison Park where he was guilty of missing a glorious chance when Villa were battling relegation late last season.
This term Smith’s team have no such concerns but having struggled in recent weeks and seen hopes of Europe fade without skipper Jack Grealish, absent through injury for the 11th straight game, this performance and result came as a timely boost.
It was already comfortably their best attacking display for several months even before El Ghazi’s strike.
Watkins, watched by England boss Gareth Southgate, was the standout, netting his 15th goal in all competitions and leading the line superbly. Were it not for the brilliance of Pickford, the 25-year-old would likely have bagged a first-half hat-trick.
Ross Barkley, meanwhile, submitted perhaps his best performance since the early weeks of the season on the return to his former club.
Everton, who still held an outside shot at the Champions League places before kick-off, were dealt a blow when James Rodriguez was injured in the warm-up and had to be replaced by Alex Iwobi in the starting XI.
Yet it was Iwobi who had the first chance of the game in the opening minute. After good work from Richarlison, his shot from the edge of the box was blocked by Tyrone Mings before Villa eventually scrambled clear.
But the visitors quickly settled, John McGinn thumping a left-footed shot over the bar before they grabbed the lead on 13 minutes.
Watkins had already come close to catching Mason Holgate and Pickford out as they tried to pass out from the back and the defender did not heed the warning.
Ambling 25 yards out, he was robbed by the striker, who then perhaps did him something of a favour by refusing to tumble under his desperate challenge, instead keeping his feet to fire low past Pickford.
Watkins was at the centre of everything. Soon after he needed treatment after being caught in the face when challenging Holgate for the ball, before being denied at close range by Pickford having been picked out by Ezri Konsa’s long ball.
Villa were well in the ascendency yet the inability to hold leads which has recently crept into their game again struck on 19 minutes. Calvert-Lewin climbed above Barkley at the far post to head home Digne’s inswinging delivery.
That ensured Emiliano Martinez would need to wait for a 15th clean sheet of the season but the goalkeeper at least ensured things didn’t get worse when he denied Calvert-Lewin a second at point blank range, the striker diving to meet Digne’s first time cross.
Then came the Pickford show as the home keeper showed precisely why he will be Gareth Southgate’s first choice heading into Euro 2020.
Twice he denied Traore in quick succession, the second with a brilliant tip over the bar after the Burkina Faso international had sent him back-peddling with an attempted lob.
The pick of the saves, however, was a point-blank stop to keep out Watkins’ effort after the striker had met Matty Cash’s cross at the far post. Barkley was unable to put home the loose ball and when it ran to El Ghazi, he smashed it off the bar.
It wouldn’t be the only time Villa struck the woodwork before the half was out. When Traore skipped away from Digne and fed Barkley, he used the run of Watkins to create space before firing a low drive off the base of the post. It was the 20th time Villa had hit the woodwork this season, the most of any Premier League team.
Watkins then had Villa’s final big chance of the half, sending a left-footed shot wide after latching on to El Ghazi’s through ball.
Having dominated for large spells, the visitors nearly went in at the break trailing after struggling to defend a series of stoppage time Everton corners.
Iwobi and Allan sent efforts off target for the home side as the second half started at the same frenetic pace as the first.
Mings was then left breathing a sigh of relief when, having only succeeded in heading a Pickford clearance into the path of Richarlison, the Brazilian couldn’t find the target with a shot from a tight angle.
The same player sent an effort straight at Martinez just past the hour mark, with Everton boss Carlo Ancelotti’s half-time tactical tweak to four-man midfield having allowed his team to take greater control over proceedings.
But Villa were still a threat, Watkins fizzing the ball across the face of goal with no-one able to supply the final touch.
Heading into the final 15 minutes and the game began to open up further. Douglas Luiz missed the chance to shoot from the edge of the area allowing Everton to break, with Calvert-Lewin slapping a shot wide from distance.
A few moments later, at the other end, El Ghazi showed far more composure, collecting a pass from Traore and stepping inside before sending a curling shot over Pickford and into the top corner.
With Villa buzzing, Traore briefly had Pickford worried with an audacious lob which just cleared the bar.
Everton were not giving up and substitute Josh King flashed a wicked drive just wide of the post but this was Villa's night.
13 - GOAL Ollie Watkins nets his 13th Premier League goal of the season to give Villa the lead. He robs a dawdling Mason Holgate, stays on his feet as the defender looks to bring him down and finishes low past Jordan Pickford.
19 - GOAL Everton draw level. Dominic Calvert-Lewin outjumps Ross Barkley at the far post to head home Lucas Digne’s corner.
35 - OFF THE POST Ross Barkley rattles the woodwork with a fierce drive from 20 yards out.
80 GOAL A brilliant strike from Anwar El Ghazi puts Villa back ahead. The Dutchman is picked out by fellow winger Bertrand Traore and curls a brilliant finish into the top corner.
Everton (4-2-3-1): Pickford; Coleman (c), Holgate, Godfrey, Digne; André Gomes (Delph 70), Allan, Sigurdsson (King 82); Iwobi (Bernard 76), Calvert-Lewin, Richarlison Subs not used: Keane, Mina, Nkounkou, Davies, Olsen (gk).
Villa (4-2-3-1):Martínez; Cash, Konsa, Mings (c), Targett; Douglas Luiz, McGinn; Traoré (Ramsey 88), Barkley, El Ghazi (Davis 90+1); Watkins Subs not used: Elmohamady, Hause, Taylor, Nakamba, Philogene-Bidace, Wesley, Heaton (gk).