The BBC Four show, which has been written by Misfits scribe Howard Overman, is based on the Douglas Adams novel Dirk Gently's Holistic Detective Agency.
The one-off episode follows Dirk as he tries to solve the disappearance of a cat and accidentally uncovers a double murder.
Mangan said: "I've been a fan of Douglas Adams ever since the Hitchiker's [Guide To The Galaxy] radio series which I used to record as a child and listen to over and over again in my bedroom. It's such a thrill now to be playing one of his brilliant characters. Dirk is a chaotic, anarchic force of nature with a totally unique take on the world. He is described as 'lazy, untidy, dismissive and unreliable'. I've absolutely no idea why they thought I'd be right for the role."
The programme will also star Cold Feet actress Helen Baxendale and Darren Boyd, who is currently appearing in Whites.
Filming for Dirk Gently has already begun and the show is expected to air later this year or in early 2011. It has previously been suggested that a full series will be considered if the episode is successful.