LOS ANGELES – On the set of NBC’s “Brooklyn Nine-Nine,” the cast goes through a precisely choreographed sequence of high-fives, including “the snake charmer,” a Pete Townsend guitar strum and a no-look, double-backhand fist explosion.

A superior officer, Ray Holt (Andre Braugher), has devised “a special punishment” for Detective Jake Peralta (Andy Samberg), the tardy squad member left out of the chorus line.

“It was absolute hell,” the proper Holt tells Peralta. “But it will be worse for you.”

RELATED

• ‘Brooklyn Nine-Nine,’ canceled by Fox, will return on NBC

It is delicious torture for the high-five aficionado, but metaphorically, it seems an appropriate celebration for “Brooklyn,” a critically acclaimed but low-rated cop comedy canceled by Fox last May but resurrected by NBC, which produces the series, for a sixth season a day later. The series returns Thursday at 8 p.m. on NBC.

Samberg says the public outcry that followed the brief cancellation – featuring the likes of superfans Lin-Manuel Miranda, Mark Hamill and Guillermo del Toro – was a surprise.

“The intensity of their appreciation caught us off guard a little bit and was maybe something that had been simmering beneath the surface. The show getting canceled gave everyone a focus point to rally around,” says Samberg, sitting in the squad’s break room, a well-worn sanctuary adorned by a beaten-up bumper-pool table, a framed list of New York labor laws and ancient coffee and candy machines.

“Brooklyn” writers were prepared for the possibility that the Season 5 closer, in which Jake marries his girlfriend and very competitive colleague, Sgt. Amy Santiago (Melissa Fumero), might be the series finale, executive producer Dan Goor says.

“We approached every other season by making the cliffhanger as dramatic as possible,” he says. But May’s finale was designed more as a “celebration,” and to make the cliffhanger “not so dire or stressful” that cancellation would have upset loyal fans. (The lingering mystery, to be resolved in Thursday’s opener, is whether Captain Holt gets promoted to police commissioner.)

NBC’s reprieve, for at least one 18-episode season, allows “Brooklyn” to explore the couple’s marriage, along with developments in the lives and careers of Holt, Sgt. Terry Jeffords (Terry Crews) and detectives Rosa Diaz (Stephanie Beatriz) and Charles Boyle (Joe Lo Truglio). Holt’s saucy civilian assistant, Gina Linetti, gets an elaborate two-part sendoff later this month as Chelsea Peretti departs. (She might return as a guest star.)

“Brooklyn’s” near-death experience revealed (and likely stoked) a deep passion for the show.

The brief cancellation “was incredibly dramatic and stressful and also wonderful and heartwarming, because we had the Tom-Sawyer-at-his-own-funeral aspect where we got to hear how much people in the world liked the show,” Goor says.

Cast and producers are especially happy to land at NBC, which has given the series a big promotional push that includes a “Die Hard”-style trailer playing off Jake’s fascination with the movie.

“NBC has a long institutional DNA with comedy,” Braugher says. “I feel like we’re in good hands. They’ve got confidence in the show. So much of what we’re doing here is going to remain stable. It’s the same studio with the same set, the same cast, the same dressing room and the same writers.”

The season premiere follows Jake and Amy on their honeymoon, while next week’s second episode puts two background figures, Hitchcock (Dirk Blocker) and Scully (Joel McKinnon Miller), in the spotlight, with a flashback that doubles as a hilarious takeoff on ‘80s TV cops.

Familiar faces, such as the Pontiac Bandit (Craig Robinson), return, and “Brooklyn” picks up continuing storylines, such as Rosa’s relationship with her parents after she came out as bisexual last season. The Halloween Heist, a fan favorite, will somehow return, even though it’s well past trick-or-treat season.

Peretti’s departure story allows her to interact with all the other precinct characters.

“I always like doing physical stuff, (but) Gina, by the nature of being at a desk and not being a cop, frequently wasn’t able to get into high-stakes, physical-comedy situations. That’s what I wanted. So I got to go out with Jake and get into some shenanigans. That was really fun for me,” says Peretti, who says she’s leaving for “a hodgepodge of reasons” but declined to be specific.

“Brooklyn” also continues to take on serious issues. In one episode, the show explores #MeToo and sexual misconduct, as an investigation Jake and Amy are working on reminds Amy of experiences from her own life.

“Some of Amy’s history comes out around that issue,” says Beatriz, who directed the episode. But “it’s not just Amy, it’s Jake. Here’s a married couple moving through this discussion about something really painful, not just for her but for both of them. #MeToo isn’t just a women’s issue.”

Lo Truglio also directs the high-five episode while playing Boyle. It creates an odd look on set as he offers guidance to actors and crew while packing a gun on his hip.

But Boyle’s puppy-dog persona doesn’t necessarily help establish authority, even if he’s armed.

“We’re all laughing about how hard it is to take him seriously because he’s in costume as Boyle,” Samberg says. “Like, ‘Alright, Boyle. Whatever you want.’”

Bill Keveney, USA Today

Read more at usatoday.com