Fans of “Brooklyn Nine-Nine” can stop tossing objects at their television screens.
A day after Fox canceled the Andy Samberg police sitcom on Thursday, NBC swooped and announced late Friday that it was picking up the series for a sixth season and 13 episodes.
“We got your SIX! #Brooklyn99 is officially coming to NBC!” the network said early on Saturday.
Robert Greenblatt, chairman of NBC Entertainment, said in a statement: “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.
“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 lineup. I speak for everyone at NBC, here’s to the Nine-Nine!”
Mr. Goor, the show’s co-creator, did a head-snapping turn on Twitter as his show died and was resurrected in the span of a day: He first thanked the show’s mournful fans for the “outpouring of support” and then whooped it up as news of the show’s revival broke.
The show, set in a police precinct of misfits, has drawn a dedicated fan base since it made its debut in 2013. In addition to Mr. Samberg, who plays Jake Peralta, an immature but smart detective, the cast includes Andre Braugher, Terry Crews, Melissa Fumero, Stephanie Beatriz, Joe Lo Truglio and Chelsea Peretti.
After Fox dropped “Brooklyn” to make room for other shows, fans like the actor Mark Hamill and the Broadway impresario Lin-Manuel Miranda used Twitter to call for its renewal.
“I ONLY WATCH LIKE 4 THINGS. THIS IS ONE OF THE THINGS,” Mr. Miranda said in a post, as the hashtags #SaveB99 and #RenewB99 ricocheted around Twitter.
According to Lesley Goldberg, TV critic for The Hollywood Reporter, the show’s producer, Universal Television, had fielded interest from companies like Hulu and Netflix to revive it, but they ultimately passed.
Mr. Samberg, an alumnus of NBC’s “Saturday Night Live” who tweets under the handle @thelonelyisland, posted on Twitter: “Thank you to everyone for the crazy outpouring of support. It means the world to us. It wouldn’t have happened without you.”
The show still has two episodes left in its fifth season.