Ferrell, 43, will join the NBC sitcom for a guest role in which he plays a branch manager who arrives from the home office and proves just as inept as Carell's Michael Scott, Deadline.com reports.
"We found Steve Carell when he was nothing but a movie star, and we turned him into a television star," executive producer Paul Lieberstein says. "We are proud to continue The Office's tradition of discovering famous talent, and we hope that once America gets a good look at Will, they'll see what we see: tremendous raw sexuality."
After seven seasons as the show's dunderheaded boss, Carell, 48, is leaving four episodes before this season's finale. Ferrell's guest role will include Carell's last three episodes, plus one more after his departure.
Ferrell reportedly called the producers and offered his services because he's a fan and wanted to give Carell a proper farewell.