PHILADELPHIA >> The gang from “It’s Always Sunny in Philadelphia” isn’t known for being charitable. The selfish, hilariously unhinged dive bar group probably shouldn’t be anywhere near a school building, but for the Philliest moment on TV this season, they wind up volunteering in the titular West Philly public school for a crossover episode of “Abbott Elementary.”

Why? Because this is their court-ordered community service for throwing 100 gallons of baby oil, 500 Paddy’s Pub T-shirts, and a Cybertruck into the Schuylkill.

The two beloved Philly-set comedies could not be more different in tone. Over its 16-season run, “Sunny” has become a crass classic fueled by wild, drunken pranks. “Abbott,” now in Season 4, has charmed viewers with a wholesome and witty mockumentary about the challenges of public education.

Unsurprisingly, it was Philly pride that connected “Sunny” creator Rob McElhenney and “Abbott” showrunner Quinta Brunson, who met at last year’s Emmy Awards and immediately began discussing a crossover.

The first crossover (the “Abbott” cast will appear in a future “Sunny” episode) aired on Wednesday night, delivering one of the funniest and cleverest shows infused with Philly attitude, authenticity, and love — plus many mentions of the city’s most endearing phrase, “Go, Birds.” (Spoilers ahead!)

Initially the “Abbott” crew, unaware of the gang’s true reasons for volunteering, are excited to receive help.

“Thank you for helping your — well, not your — a community,” says principal Ava Coleman (Janelle James) as she hands out visitor badges to South Philly’s finest: Mac (McElhenney), Frank (Danny DeVito), Dennis (Glenn Howerton), Dee (Kaitlin Olson) and Charlie (Charlie Day).

Teacher Melissa Schemmenti (Lisa Ann Walter) eyes them suspiciously and insists that they look familiar.

“Wait, did you ever get into a fight at an Eagles game?” she asks. (Of course they have. As has she.) After they exchange “Go Birds,” Ava cuts the moment short: “If Caucasian cultural exchange is over, let’s get to the free work.”

Charlie volunteers to help Jacob Hill (Chris Perfetti) with fixing his classroom’s ducts, Dee assists in Janine Teagues’ (Brunson) classroom, Mac becomes vice principal for the week, and Frank is enlisted to fight raccoons.

Dennis, though, refuses to be on camera and awkwardly exits the frame whenever the audience sees him. He does, however, manage to hit on at least one school employee.

The hilarious result of the combined writers’ rooms is revealed minutes into the show, with one joke that teetered on the edge of appropriateness. (Maybe it’s the one McElhenney said in a recent L.A. Times interview that he was shocked to see pass ABC’s standards).

Jacob describes his classroom’s finicky heat as a “Goldilocks sitch.”

Melissa replies: “You know, if a girl came into my house and ate my porridge and slept in my bed — I’m eatin’ her ass.”

The teachers lounge goes silent for a beat.

“To be clear,” she said, “in this hypothetical, I’m a bear. The animal.”