Joe Willock had given the Magpies the lead after just 18 seconds at the City Ground, but Jota Silva's second half leveller took the tie to penalties.
And Eddie Howe's side held their nerve in the shoot-out, winning 4-3, with Longstaff calmly rolling home the winner from 12 yards to send United into the third round - where they will face AFC Wimbledon away from home.
Serena Taylor was there to bring newcastleunited.com this gallery.