Brooklyn Nine-Nine is primarily a silly show about wacky cops getting up to mischief, not a source of thoughtful social commentary.

But sometimes — like on Tuesday's episode "Moo Moo," which is about what happens after Sgt. Terry Jeffords (Terry Crews), who is black, gets racially profiled by another cop — it handles meaningful subjects with grace and thoughtfulness (while remaining hilarious).

It's significant that Brooklyn Nine-Nine acknowledges this issue, considering the NYPD's ugly problems with racism. Our sitcom heroes are good cops, but they're fictional representations of a police department that as recently as 2011 had a formal structure in place that targeted black and Latino men for racist harassment and continues to protect officers who murder civilians.

Andy Samberg, Melissa Fumero, Stephanie Beatriz and Terry Crews, <em>Brooklyn Nine-Nine</em>Andy Samberg, Melissa Fumero, Stephanie Beatriz and Terry Crews, Brooklyn Nine-Nine

It's rare that a cop show seriously engages with systemic police malfeasance, and rarer still that it addresses it intelligently. But Brooklyn Nine-Nine pulled it off.

In the episode, Terry is looking for "moo moo," one of his twin daughter's security blanket that she lost while by being babysat by Jake (Andy Samberg) and Amy (Melissa Fumero). That night while he's looking for the blanket he's stopped by a white cop who asks what he's doing in "this neighborhood."

"I live here," Terry answers. When he steps toward the cop, the cop puts his hand on his gun and tells him to step back and keep his hands where he can see. Terry doesn't have has badge on him, so he's detained before he can clear up the misunderstanding.

He comes into work the next day furious and tells his his colleagues what happened. Jake has never had anything like this happen to him, because his white privilege allows him to do incredibly suspicious stuff without attracting attention (which is played out in a funny cutaway gag).

Later, Terry meets with the cop who stopped him, Officer Maldack (Desmond Harrington), to discuss what happened. Maldack apologizes for not knowing Jeffords was a cop, but not for stopping him because he's black. "You and I both know that you don't look like you belong in that neighborhood," he says.

"I'm not apologizing for doing my job," Maldack continues, summarizing the mentality of cops who commit acts of racism or violence everywhere.

"That's not the job, man," says Terry.

Terry Crews and Andre Braugher, <em>Brooklyn Nine-Nine</em>Terry Crews and Andre Braugher, Brooklyn Nine-Nine

He decides he wants to file a formal complaint against Maldack, and goes to ask his commanding officer Captain Holt (Andre Braugher) to submit it on his behalf, but Holt won't do it. That night Terry goes to Holt's house to plead his case some more, and Holt tells him that police whistleblowers face backlash from their co-workers, which is true. Holt advises him to pick his battles and rise through the department's ranks until he's in a place with the power to make large-scale changes.

But this isn't good enough for Terry.

"When I got stopped the other day, I wasn't a cop. I wasn't a guy who lived in the neighborhood looking for his daughter's toy. I was a black man. A dangerous black man. That's all he could see. A threat," Terry says. "And I couldn't stop thinking about my daughters and their future. And how one day they could be walking down the street, looking for their kid's moo moo, and get stopped by a bad cop. And they probably won't get to play the police card to get out of trouble. I don't like that thought. And I'm gonna do something about it."

He tells Holt he's going to file the complaint, even if he has to go over his head to do it.

The next day, Holt pulls Terry aside and tells him that he's filed the complaint on his behalf. Holt says that when he was a young officer and stuff like this would happen to him, he felt alone. He wanted to change things, just like Terry, but as a gay black man none of his superiors had his back. So he kept his head down and worked his way up. His advice came from an earlier time and place, but now he's finally in the position to do something about the injustice he saw and experienced.

"If I don't back you up on this, I would be betraying the very thing that I worked so hard for," he says. "So I filed that complaint."

The episode ends with Holt telling Terry that he's been passed over for a potentially career-advancing position, and they presume it's an act of retaliation. But they did the right thing, and Maldack will think twice before doing that again (this is a spot where Brooklyn Nine-Nine is softening reality for sitcom purposes. Officer Daniel Pantaleo had seven disciplinary complaints filed against him before he choked Eric Garner to death in 2014. Maldack will do it again).

Kelsey Yates, Skyler Yates, Melissa Fumero and Andy Samberg, <em>Brooklyn Nine-Nine</em>Kelsey Yates, Skyler Yates, Melissa Fumero and Andy Samberg, Brooklyn Nine-Nine

The B-story is about racism as well. Jake and Amy are babysitting Terry's twin daughters Cagney and Lacey, and the girls are asking tough questions, like if what happened to their daddy happened because he's black. Jake and Amy don't know how to respond, so they reach out to their friends for help, including Gina (Chelsea Peretti), who says, "Oh, c'mon Jake, just explain the deep-rooted institutionalized racism that remains pervasive in this country to this day." Peretti's husband Jordan Peele's movie Get Out does this, so it's probably not a coincidence that she got this line. They do eventually manage to explain it and put the girls at ease, but they still had to get kindergarteners used to the concept of racism, since as black people in America they're going to experience it.

If all of this makes "Moo Moo" sound very serious, it's not; it's filled with laughs both topical (Gina's racism song) and not (Holt's hatred of Margo and her trip to Scottsdale). It puts its medicine in a cup of pudding.

Kudos to writer Phil Augusta Jackson for his deft touch with this episode, and to Terry Crews and Andre Braugher for their excellent performances.

We're truly living in a golden age of TV comedy when a show as goofy as Brooklyn Nine-Nine can do a very special episode about a problem as serious as racial profiling and make it feel natural. And the fact that it premiered on the same day that the white officers who killed Alton Sterling in Baton Rouge won't face charges makes its theme of police racism sadly more timely. If only people in power listened to the Holts and Terrys of the real world.

Brooklyn Nine-Nine airs Tuesdays at 8/7c on Fox.