When Waylon Smithers Jr. finally comes out Sunday night after 27 years in the closet on “The Simpsons,” he won’t be the only one celebrating.

Longtime show writer Rob LaZebnik tells The Post he penned the episode in support of his own 21-year-old son, Johnny, who is gay.

“I am a Midwestern guy, so I don’t tend to wear my emotions on my sleeve, but I thought, ‘What better way to tell my son I love him than to write a cartoon about it?’ ” says Rob.

Not that the younger LaZebnik needed confirmation from an animated pop-culture icon.

“The revelation that my father loves me is not much of a revelation, thankfully. He’s unbelievably accepting,” says Johnny, a senior psychology major and film minor at Wesleyan University in Connecticut. “We’re as close as a straight dad and a gay son could be.”

Rob says he had the idea for Smithers coming out two or three years before he pitched it. He even showed an early version of the script to his son, who gave feedback and a thumbs-up. “I was really happy that someone who has experience with a gay person in their immediate family was writing the script,” says Johnny.

In fact, Rob often seeks out his son’s input, sometimes to comical effect.

“He once sent me an email, and the header was just ‘How does Grindr work?’ ” Johnny says of a time his father needed background on the gay-hookup app. “I screenshotted and Instagrammed it and sent it to all my gay friends because it made me laugh so much.”

In Sunday’s episode, Smithers — voiced by Harry Shearer — realizes his longtime longing for his boss, Mr. Burns, will never be mutual. That leads Homer Simpson to help Smithers look for better love interests.

Rob says gay storylines, even on cartoons, are important. “Sometimes TV can have a real impact on people’s thinking,” he says, adding with a laugh, “and I certainly hope it will have an impact on my son’s dating life — not that he needs help.”

Of course, it’s not really a big shock about Smithers, who was once depicted wearing a tank top and rainbow-striped short-shorts as he roller-bladed out of the Stonewall Bakery in Springfield’s gay district.

But the elder LaZebnik, 53, says Smithers was ready for a low-key reveal. “We didn’t really want to have that big moment of ‘I’m out,’ you know?” he says. “Instead, just have it be a big embrace — like everyone knows it.”

That’s not far off from Johnny’s own coming-out to his father and mother, Claire, in high school. “I was the gayest little kid, and my parents knew that,” Johnny says. “I told them I was interested in a boy. My parents were, like, ‘Yeah, we know.’ ”

Now his father even helps him with dating’s ups and downs. “My favorite thing that I’ve never heard any other dad do is, whenever I have a breakup, he’ll call me and just make sure I’m OK,” Johnny says.

And while Johnny may not fully identify with Smithers — “I’m more of a gay Lisa Simpson,” he admits — he plans to tune in Sunday. His 22nd birthday is on April 8, so the episode is “an early birthday present,” Johnny says. “I’m thinking of having a viewing party, just because this episode, not only is it written by my dad, but is especially meaningful to me.”