Yamamoto tied the game 2-2 on a deflection from the slot at 6:00.
Mercer gave the Devils a 3-2 lead on wrist shot from the left post at 11:10.
McDavid scored his second of the game on a breakaway to make it 3-3 at 7:57 of the second period.
Janne Kuokkanen scored to give the Devils a 4-3 lead at 5:14 of the third before Devin Shore tied it 4-4 on a shot from the slot at 7:06.
Yamamoto's second goal on a wrist shot at the left post gave the Oilers a 5-4 lead at 8:18 of the third.
The goal was scored on a delayed penalty call during which Hughes and Devils defenseman Dougie Hamilton each touched the puck. The Devils used a coach's challenge saying that play should have been stopped. The goal was upheld after a nine-minute review when officials said the play was not challengeable.
"I think we were obviously frustrated (with the non-review)," Hughes said. "But [Nasreddine] pulled us in and gave us a little pep talk and we went out there and executed on the 6-on-5, which was good and then in the overtime, anything can happen."
Edmonton is 2-7-1 in its past 10 games.
"It was a roller coaster game," Oilers coach Dave Tippett said. "I thought we started well, took a penalty, and boom, it's in our net. We get one right back, get one back again, and then between a challenge that wasn't a challenge ... I think four of the six goals against us were at some point deflected and bounced the right direction (for the Devils)."
NOTES:Oilers forward Ryan Nugent-Hopkins sustained an undisclosed injury midway through the third period and did not return. There was no update after the game. ... Forward Jesse Puljujarvi (20:52 of ice time), and defensemen Darnell Nurse (29:09) and William Lagesson (2:45) each returned after missing one game in COVID-19 protocol. ... This was the fourth time in NHL history that each of the first three goals of a game were scored by a No. 1 NHL Draft pick (Hughes, 2019; McDavid, 2015; Hischier, 2017). It also happened on Nov. 6, 2021 (John Tavares, 2009; Taylor Hall, 2010; Auston Matthews, 2016); Dec. 8, 2002 (Eric Lindros, 1991; Bryan Berard, 1995; Joe Thornton, 1997) and Nov. 9, 1991 (Bobby Smith, 1978; Mario Lemieux, 1984; Mike Modano, 1988).