Michael Palin will take his first leading role in a TV drama for more than 20 years in BBC1's supernatural thriller Remember Me.

Palin, who will reunite with the rest of Monty Python later this year, plays a mysterious care home resident who is the only witness to a violent death in the three-part series, which began filming in Yorkshire this week.

The star's last leading role in a small screen drama was as a headteacher in Channel 4's acclaimed Alan Bleasdale series GBH, co-starring Robert Lindsay, in 1991.

"This is my first lead role in a TV drama series since GBH. It's also a return to Yorkshire, where I was born, brought up and learned my acting in amateur dramatics," said Palin. "I was attracted to Remember Me not only by the northern setting, but also by a good, strong, challenging role, something I could really get what remains of my teeth into.

"I've always loved ghost stories, so playing the lead in one is a very exciting prospect."

Palin, who returned to the small screen last year in a supporting role in Ian Hislop's first world war black comedy drama, The Wipers Times, will play Tom Parfitt, a frail Yorkshireman whose admittance to a nursing home triggers a series of inexplicable events and a journey into an "eerie and dangerous world of lost love and betrayal".

Made by Mammoth Screen, whose credits include BBC2's Benedict Cumberbatch and Rebecca Hall drama Parade's End and ITV's Inspector Morse prequel Endeavour, Palin will star opposite The Full Monty's Mark Addy as a detective and Jodie Comer, who appeared in E4's My Mad Fat Diary, as a care assistant.

Damien Timmer, joint managing director of Mammoth Screen, said: "Michael is always top of our wish list. We have offered him so many parts over the years but he is always busy travelling the world, doing lecture tours or writing books.

"This is such a great part, and Tom goes to such unexpected places, that we thought it was worth one last attempt. It is not necessarily a part you would expect Michael to play but when we did the read through, as soon as he opened his mouth, it was just perfect. We all know he's a great dramatic actor, but he's one of our best."

Remember Me is written by Gwyneth Hughes, who wrote the BBC1 thriller Five Days, Miss Austen Regrets, also for BBC1, and the 2012 film The Girl, about Alfred Hitchcock and Tippi Hendren, starring Sienna Miller and Toby Jones.

Remember Me, which is being filmed in Huddersfield and Scarborough, will co-star Julia Sawalha and Mina Anwar.

Palin, who was one of the guest editors of Radio 4's Today over the Christmas and new year period, was last seen on TV on BBC2 documentary Wyeth's World last month, in which he explored the life and work of the American artist Andrew Wyeth.

With a third volume of his diaries due out soon, Palin will reunite with the other surviving stars of Monty Python for a string of sold-out live shows at London's O2 arena in July this year.

The BBC1 controller Charlotte Moore said: "It's a real coup for us that Michael Palin has chosen to make his return to a leading role for the first time in over 20 years on BBC1, and a testament to Gwyneth Hughes's hauntingly brilliant script."