Rainn Wilson has been cast in the CBS pilot Backstrom.

The Office star will play the lead in the comedy as well as produce the show, which is an adaptation of a Swedish book written by Bones creator Hart Hanson.

In the pilot, Wilson will play Everett Backstrom, an offensive, self-destructive detective who tries to change his bad behaviour, according to The Hollywood Reporter.

Hanson took to Twitter to announce the news of the casting, writing: "We got our Backstrom! And wow, he's a corker!"

Wilson's casting in the show comes in the wake of wrapping his nine-season run as Dwight Schrute in The Office.

The NBC show finished filming its farewell episode at the weekend.