They were the leaders of the free world, but presidents George W. Bush and Barack Obama didn’t let that responsibility get in the way of a little fun.

In the new book “Treating People Well: The Extraordinary Power of Civility at Work and in Life” (Scribner) former White House social secretaries Lea Berman and Jeremy Bernard reveal what it was like to work for their respective first families. Although they served in two very different administrations — Berman, a conservative, worked for the Bushes while Bernard, the first male social secretary in American history, was appointed by the liberal Obamas — they share how both couples were socially savvy and added levity to an otherwise high-pressure work environment.

According to Berman, Bush “understood the power of a good laugh.” In fact, he was such a good sport about his bumbling media persona that he referenced it frequently and allowed his employees to do the same; a regular gathering of top officials was renamed “The Strategery Meeting” after Will Ferrell used that word in his Bush impression on “Saturday Night Live.” Apparently, the president embraced his “Bushisms” to such an extent that “terms such as misunderestimate and ‘I’m the decider’ became part of the West Wing lexicon.” In her view, Bush embraced his frequent verbal missteps as a way to show his staff that criticism didn’t stick.

That’s not the only time Berman saw the president use self-deprecating humor to diffuse an uncomfortable situation. Once, when Bush overheard Berman’s 14-year-old daughter nervously admit she was failing high-school algebra, he rushed to her defense: “You shouldn’t worry about it,” he said. “I didn’t do very well in school either, and things turned out all right for me.”

While Bush made a practice of making fun of himself, the Obamas were known to good-naturedly tease their employees. For Bernard’s first day at the White House, he wore an orange Hermès tie that he second-guessed all morning as staffer after staffer commented on it. Then, he arrived in Michelle Obama’s office to greet his new boss. “Oh, my . . . your tie!” she exclaimed before bursting into laughter and going in for a hug. As the first lady admitted, she’d been tipped off that the tie had become a spirited point of discussion between Bernard and his new colleagues.

Bernard was not only the first male social secretary — he was the first openly gay one, too. He joined the Obama administration in 2011 and two years later, after the president was reelected, Bernard felt a hand on his shoulder at the post-inaugural ball. “I don’t want to be rude,” Obama said, “but I gotta say . . . for a gay man you really are a bad dancer.” They both chuckled and for the rest of his time at the White House, Bernard’s questionable moves on the dance floor became a running joke between the two men. Bernard reveals that he and the president even had a “Jeremy Dance,” which they performed together at holiday galas after the guests had left. In 2015, when Bernard left the White House, the pair did one last rendition, which was famously caught on camera.

But before he exited the administration, it’s clear that Bernard could give as good as he got. One afternoon, when the first lady was scheduled to do a taping with Jimmy Fallon, Bernard was tasked with showing the late-night host around the White House. When they arrived at the Diplomatic Reception Room, Bernard says Fallon took in the modest spread — mostly bottled water and apples — and joked he was less than impressed. Bernard was quick with his retort: “We do a little better for Leno when he’s here.”

Bernard might have learned a thing or two from his predecessor, former Obama social secretary Julianna Smoot. Sometime during her tenure, Jay-Z and Beyoncé showed up for a state dinner, where Beyoncé was set to perform afterwards. Chatting with the couple, Smoot could tell that the superstar singer was nervous. Then, Mexican magnate Carlos Slim walked by — at the time, the richest man in the world. “There goes someone even richer than you two,” Smoot said, at once making her guests laugh and clearing the air.

Social secretaries are responsible for booking musical acts, and it was in this capacity that Lea Berman eventually saw the threshold of her boss’ affability. During the war in Iraq, Bush requested a visit from a popular country singer. But when Berman called to book the star, his manager said an emphatic, “Hell no.” Apparently, the star objected to the war and wanted nothing to do with the president.

When Berman delivered the news to Bush, she says he was visibly upset. Even the thick-skinned president had a sore spot. Berman vowed that next time, she would be more sensitive. When it comes to treating people well, blunt honesty isn’t always the best policy.