The winger cracked a fine shot in off the post from just outside the box in the second minute of additional time at Goodison Park as the Toffees claimed their first victory in nine Premier League outings.
The hosts had equalised in the 79th minute when Richarlison – having had two efforts disallowed after VAR checks – headed in on the follow-up when Gray’s strike came back off the bar, cancelling out Martin Odegaard’s opener just before the break.
Gray, who has scored five goals and provided two assists since joining Everton over the summer from Bayer Leverkusen, told Sky Sports: “It was a crazy moment, my best moment here so far.
“It was important for us to get that win. Last game I said I had a feeling it was around the corner.
“As a group, we have gone through this bad patch, it has been tough but we have stuck together. We are an experienced squad and with the fans like that, behind us for the whole game, it was more than deserved.”
Everton headed into the fixture with just two points taken from the last 24 on offer, and the aftermath of last week’s 4-1 loss to Liverpool having seen Marcel Brands leave his role as director of football, while the club said boss Rafael Benitez would continue to receive owner Farhad Moshiri and the board’s “full support”.
In the 27th minute of the match, a small number of Everton fans left their seats in a protest over the running of the club, with it being 27 years, come 2022, since they last won a trophy.
There was also vociferous support for the team at various points of the contest, and delirium among the crowd at the dramatic finale.
A notable omission from Everton’s matchday 20 was Lucas Digne, who had played the full duration of Wednesday’s derby.
When Benitez was asked why the French full-back was not involved, he said: “I think as a manager you have to make decisions and you have to do your team selections.
“I decided Ben Godfrey could be a good option for us for this game, and he did really well, so I’m really pleased about that, and that’s it. The main thing is to be sure the team is performing and we have the right mentality.”
Everton moved up from 16th to 12th in the table, going eight points clear of the relegation zone. They are now five behind seventh-placed Arsenal, for whom it was a third defeat in four matches.
Gunners boss Mikel Arteta expressed his frustration over his team’s performance, which included substitutes Eddie Nketiah and Pierre-Emerick Aubameyang failing to make the most of good chances at 1-1 and 2-1 respectively.
Nketiah came on for Gabriel Martinelli, who Arteta said had sustained a hamstring problem.
When asked about Nicolas Pepe being on the bench and Nketiah being brought on for Martinelli rather than the Ivory Coast international, Arteta said: “I decided to play Eddie today, to bring him on. He created three chances and hit the post once in 25 minutes I think.
“He does every day in training what you see him do in 25 minutes here. Every single day. That’s why I picked him.”