Fresh off of lensing the finale of “The Office,” Rainn Wilson has signed on to star as a self-destructive police detective in the CBS drama pilot “Backstrom.”

The 20th Century Fox TV project is based on a Swedish book series about an irascible detective who struggles to change his behavior. “Bones” exec producer Hart Hanson penned the adaptation, which garnered a hefty commitment from CBS. Role marks a dramatic departure for Wilson, who is known for his comedy work.

Dennis Haysbert and Kristoffer Polaha are already cast in supporting roles as fellow police officers.

Hanson exec producers with Leif G.W. Persson, who penned the books, and Persson’s rep, Niclas Salomonsson.

Wilson has spent the past nine seasons on NBC’s “The Office,” which wraps in May. NBC had developed a spinoff revolving around Wilson’s Dwight Schrute character but opted not to go forward with it as a series.

His pic credits include “The Rocker,” “Hesher” and “Super.”