It was late 2013 and Obamacare was in trouble. HealthCare.gov, the website where people could sign up for coverage under the Affordable Care Act, had been marred by major technical problems and there was concern in the White House that not enough people would be able to obtain health insurance ahead of the pending deadline.

Around that time, President Obama’s senior adviser Valerie Jarrett convened a meeting with entertainers to brainstorm ideas on how to get young people to buy insurance plans on the exchanges before it was too late. Among them was comedian Scott Aukerman, co-creator of Funny or Die’s Between Two Ferns with Zach Galifianakis and the writer-director of Netflix’s new Between Two Ferns: The Movie.

“It was a bunch of Hollywood players trying to come up with ideas for videos that would steer people to the Affordable Care Act,” Aukerman tells me on this week’s episode of The Last Laugh podcast. “And I think a lot of that stuff is really lame. The reason it can be really lame is everyone’s so protective of what gets out there into the world. So if you see a politician on a late-night talk show, if they’re reading jokes, all I can think about is the speechwriters that have gone through and red-lined jokes. They all seem so safe. They don’t seem dangerous at all.”

When it was Aukerman’s turn to speak, he suggested that Obama appear on Between Two Ferns, the web series in which the host Zach Galifianakis is known for insulting celebrities like Bradley Cooper, Jennifer Aniston and Justin Bieber to their faces. “That was my only idea,” he admits.

A few months passed and Aukerman’s idea started to look like it might actually happen. “When it finally became something that it seemed like he was going to do, you start having their people try to shape it and preemptively try to get in there and be like, ‘Well let’s talk about what’s really going to happen,’” he says of the White House staff. He says they told him, “Obviously, you can’t do it like a real Between Two Ferns.”

Cody Keenan, who had recently taken over the job of Obama’s head speechwriter from Jon Favreau, was tasked with making sure the president’s message was represented in the video.

“The final product had to balance a few things,” Keenan tells me by email. “It had to remain true to what Between Two Ferns is, or why would Funny or Die do it? It had to plug the ACA as much as possible, or why would we do it? Simply put, it had to walk the line between remaining authentic for fans, and attractive to the people we were trying to reach. But it also had to protect the dignity of the office of the president of the United States.”

“We weren’t worried about President Obama’s comic chops,” Keenan adds, “or the critics who’d clutch their pearls no matter what—but we wouldn’t put him in a situation that was embarrassing or too off-color.”

“So that’s what happened,” Aukerman says. “And that’s what’s happened a few times in my life where the opportunity is great, but it’s not worth it if they’re going to make you compromise to that extent. So I just kind of had to lay down the law. This is the way we do it. We have to have final cut over it. Yes, we can talk about jokes that you don’t want in there, but we have to be able to make hard jokes, otherwise this is pointless.”

Initially, Aukerman says Obama’s communications staff “really got behind that.” He and Galifianakis put a loose script together for their approval. “There was one joke where Zach says, ‘How does it feel to be the last black president?’ which kind of seems prescient at this point,” Aukerman says. “Obama’s people were like, ‘Hey, that’s just not going to fly.’ And I said, ‘Oh man, that’s the funniest joke.’”

After some back and forth, Obama’s staff relented. According to Aukerman, Keenan said, “You know what? I spend all day cutting stuff out because of how people are going to react to it. I don’t want you guys to go through that. Go ahead, do the joke.”

But then, right before they were about to shoot the video in the White House, Galifianakis came up to Aukerman and said, “Hey, I’m cutting this joke.” Aukerman told him, “No, no, no, you have to do it!” to which Galifanakis replied, “No, he’s not going to like it if I say it.’” Aukerman had to convince Galifianakis that it was approved and Obama was “expecting” him to ask it. “It will throw him if you don’t,” Aukerman told him. “So that’s how we got it in.”

For his part, Keenan says he doesn’t remember “ balking” at “the last black president” joke, adding, “I remember thinking it was funny. It’s possible other people on staff had a different view.” There was, however, one other joke about the president’s “sex life” that he dismissed outright. “That’s the only thing I wouldn’t budge on,” he says.

According to Keenan, in between takes Galifianakis kept saying “I can’t believe you guys are letting us do this.”

When Galifianakis was on Conan in 2016, he revealed that he thought of another joke when he went to the White House mess hall and saw that there was a dessert called “Chocolate Freedom.” He considered asking Obama if the dessert was named after him, but ultimately decided he couldn’t do it. “President Obama would have said yes,” Keenan tells me.

In the final cut, Obama answered Galifianakis’ “last black president” question by asking, “Seriously? What’s it like for this to be the last time you ever talk to a president?”

Neither Keenan nor Aukerman can remember if that retort was improvised or fed to the president. “But he knew what he was getting into,” Keenan says, explaining that he showed Obama the Bradley Cooper and Ben Stiller episodes of Between Two Ferns right before they filmed with Galifianakis.

The president must have had the Hangover movies on his mind because he did ad lib the lines about Cooper “carrying” those films and one making fun of the third sequel. “If I ran a third time, it would be sort of like doing a third Hangover movie,” Obama joked. “Didn’t really work out very well, did it?”

After they finished shooting, a transcript circulated around the White House and Aukerman got word that people on Obama’s staff thought it was really funny.

“But even then, we were celebrating that night and some of Obama’s people came up to me and said, ‘So that was really funny, but obviously it can’t be like that ,’” Aukerman recalls. “‘Right now you have a six-minute video where you talk about the Affordable Care Act for the last 30 seconds. Obviously we have to make it like a three-minute video where most of it is talking about Affordable Care Act.’”

“And I was like, ‘No, that makes it not cool anymore.’ It just makes it an ad and no one will share an ad,” he says. “No one cares about an ad. So I kind of put my foot down and said, ‘No it’s got to be this ratio of jokes to Affordable Care Act. And I wish more people would learn that lesson when it comes to doing stuff in politics.”

Ultimately, it worked. The episode premiered on Funny or Die on March 11, 2014, about three weeks before the extended deadline to sign up for insurance. Quickly, the video garnered tens of millions or views and Funny or Die became the top referrer to HealthCare.gov, which saw a 40 percent traffic increase the day it came out.

“ The video certainly helped drive signups,” Keenan acknowledges, adding, “The media environment had changed so much so quickly that people were no longer getting their trusted information solely from the legacy news outlets, but from all sorts of places. And so we were trying to go everywhere to reach people where they were.”

A few days later, Galifanakis sent Keenan a thank-you email followed up by a bucket of beers while Funny or Die gave the speechwriter a gold-painted fern statue that reads “Cody Keenan: Congratulations on 20 million views and 8 million signups!”

The Obama video was such a success that two years later, Hillary Clinton specifically requested to make an appearance on Between Two Ferns.

To Clinton’s “credit,” Aukerman says that her campaign staff imposed no restrictions on them when she came in to do the show during her 2016 run. “She wanted to do it,” he says. “We had heard Barack Obama wanted to do it and found out later he had no idea what he was doing.”

“So yeah, they let us do what we wanted to do and just made it funny,” Aukerman continues. “Now did it work for them like it worked for the ACA? I guess not! We maybe even hurt her chances.”

Now that they’ve turned the web series into a Netflix movie, Galifianakis has suggested to Aukerman that this could be “the end of Between Two Ferns.” But they are not ruling out the possibility of hosting the Democratic presidential candidate ahead of the 2020 election.

Aukerman says they would only do it if they felt like there was enough material for Galifianakis to make fun of. “If they had a campaign that was like Justin Bieber’s career then sure,” he says. “But who knows?”

Subscribe to The Last Laugh on Apple Podcasts here. On next week’s episode: Stand-up comedian and host of MTV’s The Tom Green Show, Tom Green.