NBC has picked up “Brooklyn Nine-Nine” for a sixth season, the network announced Friday.

The decision comes after the cop comedy was canceled at Fox after five seasons on Thursday. Producer Universal Television had been in talks with Hulu to keep the series afloat, but the streaming service ultimately passed.

The sixth season will consist of 13 episodes.

“Ever since we sold this show to Fox I’ve regretted letting it get away, and it’s high time it came back to its rightful home,” said Robert Greenblatt, chairman of NBC Entertainment. “Mike Schur, Dan Goor, and Andy Samberg grew up on NBC and we’re all thrilled that one of the smartest, funniest, and best cast comedies in a long time will take its place in our comedy line-up. I speak for everyone at NBC, here’s to the Nine-Nine!”

With the move, series executive producer and co-creator Schur will have three shows on NBC for the 2018-2019 season. Along with “Brooklyn Nine-Nine,” NBC also airs the critically-acclaimed single-camera comedy “The Good Place” and will air the recently-ordered multi-cam “Abby’s,” about an unlicensed bar in San Francisco.

It will also mark a homecoming of sorts for Samberg, who was previously a cast member on “Saturday Night Live.”

Fans of “Brooklyn Nine-Nine” were stunned when Fox announced they were cancelling it along with fellow comedies “The Mick” and “The Last Man on Earth.” There has been a large online push to save the show, with celebrity fans like Lin-Manuel Miranda leading the charge by sharing hashtags like #SaveB99 and #RenewB99. Mark Hamill also expressed his dismay at the show’s cancellation in a tweet on Thursday.

The cast includes Samberg, Andre Braugher, Terry Crews, Melissa Fumero, Joe Lo Truglio, Stephanie Beatriz, Chelsea Peretti, Dirk Blocker, and Joel McKinnon Miller.

Schur, Goor, David Miner and Luke Del Tredici executive produce. Universal Television, Fremulon, Dr. Goor Productions, and 3 Arts Entertainment produce.