The 28-year-old was born in Newcastle and started his career with the Magpies at Academy level before joining Carlisle United in 2008 at the age of 16.
He went on to make 180 appearances for the Cumbrians before moving to Walsall in the summer of 2017. After a season with the Saddlers, he moved on to Scottish Premiership side Motherwell where he established himself as their number one, helping the Well to finish third last term.
A boyhood Magpies supporter, the tall and agile shot-stopper will provide further competition for Martin Dúbravka and Karl Darlow following the departure of the long-serving Rob Elliot.
"It's an unbelievable feeling for me to sign for Newcastle," said Gillespie. "Being a supporter all my life and to be released at 16 was disappointing, but I have gone away, worked hard and now I'm back, and I can't wait to make the most of an opportunity every Geordie would dream of."
Head coach Steve Bruce added: "We're very pleased to welcome Mark aboard. He was here when he was young and has gone on to do very well.
"He'll give us really healthy competition with our goalkeepers and we wish him the very best of luck."