Yoshinori Muto and Miguel Almirón drew United level in the second half after George Saville and Britt Assombalonga had given the visitors a comfortable lead before the break.
Then Joelinton grabbed a late winner, the Brazilian receiving a throw-in from Javier Manquillo with his back to goal before spinning past former Sunderland man Paddy McNair with a deft first touch and slotting home with his second.
The frontman had arrived as one of eight changes midway through the second half - Almirón had also entered the fray along with the likes of Allan Saint-Maximin and skipper Jamaal Lascelles - and Newcastle got better as the game went on, which will please head coach Steve Bruce with his side's return to Premier League action against Sheffield United now very much on the horizon.
Bruce will look for improvement in the defending for Boro's first goal, which saw Saville race onto Ravel Morrison's pass and stabbing home despite Fabian Schär's best efforts.
The Teessiders' second, though, was a fantastic strike from Assombalonga, who spectacularly beat Martin Dúbravka from outside the box after Ashley Fletcher's neat lay-off.
Newcastle pulled one back at the beginning of the second half when Muto drove at the backpedalling Boro defence and finished well from just inside the penalty area.
And the Magpies deservedly levelled through Almirón, who was adjudged to have stayed onside when he received Saint-Maximin's pass and found the net. Newcastle first team coach Steve Harper was the referee, while a member of staff from each club were his assistants.
Then, in the final minute, Joelinton produced his moment of magic - a timely boost for him and the Magpies as they continue to prepare for their return to serious action later this month.
Newcastle United: Martin Dubravka (Karl Darlow 46), Emil Krafth (DeAndre Yedlin 65), Fabian Schar, Federico Fernández (Florian Lejeune 65), Danny Rose, Matt Ritchie (Jamaal Lascelles 65), Isaac Hayden (Nabil Bentaleb 65), Jonjo Shelvey (Javier Manquillo 65), Valentino Lazaro (Allan Saint-Maximin 65), Christian Astu (Miguel Almirón 65), Yoshinori Muto (Joelinton 65).
Photograph courtesy of Middlesbrough Football Club