The 20-year-old’s previous contract expired at the end of the 2019/2020 season and had been linked with a move to Italian Serie A side Udinese.
Longstaff will however remain at the Saint James’ Park for the time being after agreeing fresh terms.
Longstaff, whose older brother Sean is also with the Newcastle first team, came through the club’s academy and made a goalscoring Premier League debut against Manchester United last October.
He ended the campaign with 15 appearances across all competitions as Steve Bruce’s men finished in 13th place.
"I'm delighted to have signed. It took a bit longer than I'd hoped but I'm really happy it's done now, and I can't wait to get back to playing at a full St. James' Park hopefully soon," Longstaff told the club's website.
"I spoke to (manager) Steve Bruce and we talked through it and it was a no-brainer after I spoke to him. He gave me my chance and I'm really looking forward to working with him and his coaching staff, who were all great with me."
Bruce said: "It's great to see a young local lad from North Shields staying with his boyhood club. It's taken a while, but patience is a virtue and I've always said that I was quietly confident."
Newcastle are away to West Ham United on the opening game of the 2020/2021 season.