The Downton Abbey actor will play the title role of tramp Mr Stink in BBC One's adaptation of the Little Britain comic's children's novel.
The book follows the story of a schoolgirl who forges a friendship with a homeless man that hides in her family's garden shed.
Walliams, who will himself appear as the Prime Minister, said: "I am thrilled that Hugh is playing Mr Stink. He is one of the most popular and talented actors around, and is the perfect person to bring out the character's humour and sadness."
Bonneville added: "I'm delighted to be adding my own whiff to the odour that emanates from David Walliams... and his very funny, touching and thought-provoking story."
Meanwhile, the corporation also confirmed that the script would be adapted into a 60-minute special by Walliams and Simon Nye.
Harish Patel, known for roles in Run, Fatboy, Run and Coronation Street, has also been cast as middle-aged newsagent Raj.
Filming for the show begins next month with transmission due before the end of the year.