Toffees defender Jarrad Branthwaite had nodded Iliman Ndiaye's inswinging corner in off the upright to open the scoring on 19 minutes after a cagey start to the contest.
Jacob Ramsey's deflected drive then levelled matters on Tyneside after a slow start from the hosts.
But Beto pounced just after the half hour to prod home from close range after goalkeeper Nick Pope could only parry Dwight McNeil's effort from the edge of the box.
Jacob Murphy's deflected volley from a Joelinton cross drew United level with less than ten minutes remaining - but just seconds later, Barry turned Kiernan Dewsbury-Hall's cross in to put the Toffees back in front.
Ndiaye lifted a 25-yard effort well over Pope's crossbar early on, while Joelinton curled a shot over after Anthony Gordon's lay-off before Branthwaite struck.
United struggled to carve out any gilt-edged chance in the first half hour, with Joelinton seeing a tame header held by Jordan Pickford and Elanga shooting straight at the England stopper from distance.
After Sandro Tonali picked him out on the edge of the box, Ramsey's drive restored parity - but only momentarily, as Beto's close-range finish put the visitors back in front.
Pope saved comfortably from McNeil soon after the restart, while Kieran Trippier whipped a free kick wide of the target before the hour as Newcastle sought a second equaliser of the afternoon.
A spell of pressure from United followed, with Gordon cutting inside and seeing his low shot parried by Pickford, with some last-ditch defending from Beto and James Tarkowski preventing the rebound from being turned in.
The hosts were enjoying the vast majority of possession but with 25 minutes left, Everton squandered a golden opportunity to extend their advantage. Beto pursued a loose ball to the touchline alongside Malick Thiaw, and though the ball looked to have gone out of play, referee Stuart Attwell allowed the game to continue as Beto ran clean through on goal. Under pressure from Tonali, his shot clipped the crossbar as boos rang round St. James'.
Substitute Harvey Barnes - sent on with Murphy as Howe looked for a spark - cleared the crossbar when a Trippier cross fell his way via a touch from Pickford and another replacement, Joe Willock, also fired over as the hosts continued to push.
With Yoane Wissa also deployed from the bench, Gordon and Barnes both saw shots blocked before Murphy connected well with Joelinton's lofted centre to level once more, with the winger's effort taking a touch off an Everton defender on its way past Pickford.
But after the Magpies surrendered possession deep in their own half, Dewsbury-Hall burst into the box and Toffees substitute Barry - under pressure from Lewis Hall - turned home the cross to stun the United faithful.
Magpies head coach Eddie Howe had made six changes to his side for the visit of David Moyes' men, with Pope, Lewis Hall, Malick Thiaw, Ramsey, Elanga and former Everton forward Gordon all restored to the line-up.
**Newcastle United:** Nick Pope, Kieran Trippier (c) (Yoane Wissa 76), Lewis Hall, Joelinton, Sandro Tonali, Anthony Gordon (Will Osula 86), Malick Thiaw, Anthony Elanga (Jacob Murphy 56), Nick Woltemade (Harvey Barnes 56), Dan Burn, Jacob Ramsey (Joe Willock 46)
**Subs not used:** Aaron Ramsdale, Sven Botman, Alex Murphy, Leo Shahar