Longstaff's emphatic strike opened the scoring for the Magpies in the early stages of the festive friendly on Tyneside before Chris Wood's second-half penalty doubled the hosts' advantage in front of a respectable crowd of 34,956.
Matt Targett's unfortunate own goal halved the deficit in the closing stages before United held firm to record the victory in their final warm-up match before the resumption of the 2022/23 season.
Eddie Howe made four changes from the side which lifted the Diriyah Season Cup following a 5-0 win against Al Hilal in Riyadh last week as Kieran Trippier and Nick Pope were named in the starting line-up after the pair returned from international duty this week following England's run to the World Cup quarter-finals in Qatar.
Targett and Longstaff were also handed starts, replacing Jamal Lewis and Joelinton respectively while the substitutes' bench featured a number of Academy youngsters competing regularly for the Magpies' under-21 side.
The visitors, occupying eighth spot in La Liga, went close to taking the lead inside the opening two minutes as Chris Wood's back pass was intercepted by Raúl de Tomás Gomez before the Spaniard's fierce strike at goal was importantly tipped over the crossbar by Pope.
In the 4th minute, Newcastle took the lead through Longstaff's excellent finish. As Trippier's teasing cross from the right flank was half cleared into Jacob Murphy's path, the winger picked out Longstaff who rifled the ball into the roof of the net.
Longstaff went close to doubling his and United's advantage minutes later as the North Shields-born midfielder latched onto Murphy's pass but the 25-year-old's strike towards goal was blocked out for a corner.
Newcastle continued to push for a second goal as Trippier threaded a neat pass into Murphy's path but the forward's drilled effort was beaten away by Vallecano goalkeeper Stole Dimitrievski.
In the second half, Allan Saint-Maximin almost completed a neat attacking move from the hosts as the Frenchman cut inside from the left flank before his low effort was held by Dimitrievski.
In the 69th minute, Newcastle extended their lead through Wood's spot-kick. After Joe Willock was bundled over inside the box, the New Zealand international fired an impressive penalty into the top left-hand corner.
Newcastle's goal cushion was reduced to one in the 75th minute as Targett inadvertently turned the ball into his own net past a helpless Pope following a low cross into the penalty area.
Pope was on hand to preserve Newcastle's lead after holding Sergio Camello's half volley after the Vallecano substitute was granted space inside the box.
Teenage pair Jay Turner-Cooke and Lewis Miley were both introduced from the substitutes' bench, making their senior home debuts in the process, and combined neatly before the latter's drilled cross was turned away from danger.
Newcastle United resume their 2022/23 campaign on Tuesday night when Howe's side host AFC Bournemouth in the Carabao Cup fourth round (kick-off 7.45pm GMT).
Newcastle United: Nick Pope, Kieran Trippier (Lewis Miley 83), Jamaal Lascelles (c), Sven Botman, Matt Targett, Jonjo Shelvey, (Jay Turner-Cooke 76), Sean Longstaff, Joe Willock, Jacob Murphy, Allan Saint-Maximin, Chris Wood (Dylan Stephenson 76).
Substitutes: Mark Gillespie, Alex Murphy, Niall Brookwell, Nathan Carlyon, Josh Scott, Kyle Crossley, Michael Ndiweni.