Whatever news gods decided that the cable television stars Tucker Carlson and Don Lemon should be fired the same week that President Biden was scheduled to give a funny speech ribbing the news media certainly were generous in providing fresh material. And Mr. Biden took advantage on Saturday night as he gleefully mocked some of his favorite foils.

In his annual appearance at the black-tie White House Correspondents’ Association dinner, the one night a year that a president is expected to play a stand-up comic, Mr. Biden made the most of the opportunity with some timely skewering of those who usually skewer him — most notably Fox News, which fired Mr. Carlson on Monday just days after settling a defamation lawsuit for $787.5 million.

“Last year, your favorite Fox News reporters were able to attend” the dinner “because they were fully vaccinated and boosted,” Mr. Biden said, in a nod to his coronavirus response strategy. “This year, with that $787 million settlement, they’re here because they couldn’t say no to a free meal.”

“And hell, I’d call Fox honest, fair and truthful,” he told the crowd gathered in a cavernous ballroom in Washington as well as a national television audience watching at home. “But then I could be sued for defamation.” When some groaned, he quipped, “It ain’t nothing compared to what they do to me.”

Mr. Biden also went after CNN. Just five days after the financially struggling network fired Mr. Lemon following comments that a woman in her fifties is past her prime, the president ribbed, “CNN was like, ‘Wow! They actually have $787 million? Whoa!’”

At another point, Mr. Biden managed to jab both Fox and CNN while deflecting questions about his age as he seeks re-election. “You might think I don’t like Rupert Murdoch,” the 80-year-old president said of the 92-year-old Fox impresario. “That’s simply not true. How can I dislike a guy who makes me look like Harry Styles?

“You call me old?” Mr. Biden went on. “I call it being seasoned. You say I’m ancient? I say I’m wise. You say I’m over the hill? Don Lemon would say that’s a man in his prime.”

The dinner came at the end of a chaotic week for the media as the chattering classes descended on Washington for their annual ritual of schmoozing, drinking, and gossiping. The industry is reeling from a steady drumbeat of layoffs and closures, but it was the firings of the two high-profile, millionaire cable personalities that had everybody talking.

In its second year since the pandemic, the dinner has mushroomed into an even more splashy spectacle. Like the wedding of a wealthy family, it has now replicated into multiple events spread over five days, with the first pre-dinner parties and receptions starting Wednesday night and the last post-dinner brunches scheduled for Sunday.

Politico’s Playbook, the newsletter that obsessively covers all things Washington, included “spotted at” guests lists for 14 events on Friday night, a full 24 hours before the dinner itself. Some of the buzziest parties were hosted by media start-ups intent on establishing themselves, including Crooked Media, Axios and Semafor.

The late-night party hosted by United Talent Agency, which represents many television news anchors and correspondents, drew the most interest. Mr. Lemon, a client, showed up ready to mingle with a crowd that included the actress Cobie Smulders, Governor Gavin Newsom of California and Jen Psaki, the White House press secretary-turned-MSNBC host. At one point, the man responsible for Mr. Lemon’s ouster, CNN chief executive Chris Licht, was at the party too, although it was unclear if the two spotted each other.

The hottest ticket on Saturday night was the after-party hosted by the media mogul Byron Allen and the news website The Grio at the Smithsonian National Museum of African American History and Culture. The event was honoring Gayle King of CBS News and Diana Ross was scheduled to perform. On Sunday, brunches hosted by CNN and Politico will mark the end of the festivities.

The Wall Street Journal’s new editor in chief, Emma Tucker, hosted a pre-dinner reception on Saturday. Attendees wore #freeEvan stickers, referencing Evan Gershkovich, its reporter imprisoned in Russia and accused of espionage, which the Journal and the U.S. government have denied.

Mr. Biden opened his act with comments about Mr. Gershkovich and other Americans held overseas. “Everyone in this hall stands with you,” the president said, addressing Mr. Gershkovich’s family, who was in attendance. “We’re working every day to secure his release, looking at opportunities and tools to bring him home. We keep the faith.”

He also mentioned Austin Tice, a journalist held in Syria for nearly 11 years, and Paul Whelan, a former U.S. marine serving a 16-year prison sentence in Russia on what the United States says are fabricated charges of espionage. Mr. Biden pointed in the audience to Brittney Griner, the W.N.B.A. star freed in a prisoner swap in December after being detained for nearly 10 months in Russia. “Boy, I can hardly wait to see you back on the court, kid,” he said.

Mr. Biden’s supportive comments about a free press contrasted sharply with former President Donald J. Trump, who constantly called reporters “enemies of the people” and their reports “fake news.” But Mr. Biden gingerly acknowledged his own reluctance to engage with the reporters who cover him other than in passing. He has given fewer news conferences per year than all but two presidents since Calvin Coolidge and fewer interviews than any modern president. Alluding to this, Mr. Biden said his dinner speech would be like his press interactions: “I’ll talk for 10 minutes, take no questions and cheerfully walk away.”

He made a few passes at Mr. Trump and Gov. Ron DeSantis of Florida, his would-be Republican challengers. Mr. Biden joked that he had created 12 million jobs “and that’s just the lawyers” defending Mr. Trump. As for Mr. DeSantis, who has generated attention for his war with Disney, Mr. Biden said he had prepared plenty of jokes “but Mickey Mouse beat the hell out of me, got there first.”

He went after congressional Republicans as well. Telling dinner attendees to be safe, he said, “If you find yourself disoriented or confused, it’s either you’re drunk or Marjorie Taylor Greene.” Noting that his approval rating stands at 42 percent, he said, “Kevin McCarthy called me and asked me, ‘Joe what the hell’s your secret?’”

The featured comedian of the evening, Roy Wood Jr., a correspondent on the Comedy Channel’s “The Daily Show,” poked gentle fun at Mr. Biden. As he followed the president to the podium, Mr. Wood held up papers and told Mr. Biden, who faces a special counsel investigation into the mishandling of secret papers, “I think you left some of your classified documents up here.”

Mr. Wood noted that protesters in France rioted over the retirement age being raised to 64 and contrasted that with Mr. Biden. “We have an 80-year-old man begging us for four more years of work,” he said. Noting the president’s “let me finish the job” mantra, Mr. Wood added, “That’s not a campaign slogan. That’s a plea.”

Mr. Biden ended on a serious note, discussing the case of Emmett Till, the 14-year-old Black boy whose brutal murder in Mississippi in 1955 galvanized the civil rights movement. Mr. Biden, who hosted a showing of “Till,” a feature film about the case, at the White House, finished with a plea to fight for democracy.

“We know in our bones and you know it too our democracy remains at risk,” he said. “But I’ve also made it clear, as I’ve seen throughout my life, it is within our power, each and every one of us, to preserve our democracy. We can, we must, we will.”