Meta Platforms has donated $1 million to president-elect Donald Trump ’s inaugural fund, the latest step by CEO Mark Zuckerberg to bolster his once-fraught relationship with the incoming president.

The donation, confirmed by the company, is a departure from past practice by Zuckerberg and his company, and comes after an election campaign in which Trump threatened to punish the tech tycoon if he tried to influence the election against him.

The contribution and efforts to court the incoming administration are emblematic of the balancing act for technology CEOs whose companies have often been the target of ire from Trump and other Republicans and whose workforces tend to lean strongly to the left.

Now, with Republicans set to take control of the White House and both houses of Congress and calling for new regulation of tech, some executives are adopting a new posture toward Trump.

Amazon founder Jeff Bezos , long a foe of the president-elect, congratulated Trump on X after the election for “an extraordinary political comeback and decisive victory,” and said this month that he’s “actually very optimistic this time around.” Speaking at a New York Times conference, he said: “What I’ve seen so far is that he is calmer than he was the first time and more confident, more settled.”

Zuckerberg’s efforts to strengthen ties—which began years earlier—included a November dinner with Trump on the patio of his private Mar-a-Lago club in Palm Beach, Fla., that focused on general relationship-building.

The dinner capped a two-day flurry of meetings for Zuckerberg advisers at Mar-a-Lago. Senior Meta policy executives Joel Kaplan and Kevin Martin and Republican strategist Brian Baker met with incoming White House chief of staff Susie Wiles, according to people familiar with the matter.

Zuckerberg and his advisers met with Sen. Marco Rubio, Trump’s nominee for secretary of state, as well as with three senior incoming White House advisers: Stephen Miller , Vince Haley and James Blair.

Before the dinner, Zuckerberg did a private demonstration for Trump of Meta’s Ray-Ban smart glasses , which he gifted to the president-elect, the people familiar with the discussions said.

Zuckerberg’s team told the inaugural fund before the dinner that Meta planned to donate, one of the people said.

Federal campaign-finance reports show Zuckerberg has supported congressional candidates in both parties over the years and has largely stayed out of presidential races.

Neither Zuckerberg nor Meta donated to Trump’s inaugural fund in 2017 or to President Biden’s fund in 2021, according to public records. Both of those funds drew in $1 million donations from fewer than a dozen major corporations, including many of the same companies.

The Zuckerberg-Trump relationship has oscillated over the years. In January 2017, FWD.us, a lobbying group founded by Zuckerberg and other tech leaders supporting immigration reform, contributed $5,000 to Trump’s transition, according to public records. Weeks later, Zuckerberg criticized Trump’s executive orders around immigration, writing in a Facebook post: “Like many of you, I’m concerned about the impact of the recent executive orders signed by President Trump.”

Trump and Zuckerberg remained in touch over the course of his presidency. In 2019, they met in the Oval Office. In 2020, Trump said he had recently had dinner with Zuckerberg, who he said had congratulated him for being “No. 1 on Facebook.”

After Trump supporters invaded the U.S. Capitol on Jan. 6, 2021, Facebook suspended Trump from posting, as did several other social-media platforms. Following that, Trump issued a statement saying: “Next time I’m in the White House there will be no more dinners, at his request, with Mark Zuckerberg and his wife. It will be all business!”

In the fall of 2021, Zuckerberg and his wife, Priscilla Chan , hired Baker, a strategist who has long worked for the family of former Republican National Committee finance chairman Todd Ricketts , to help them make inroads with Republicans, according to people familiar with the matter. Baker’s job: to explain to Trump aides and Republican officials the context of $400 million that Zuckerberg and Chan gave in 2020 to help state and local governments pay for election infrastructure during the pandemic.

Republicans accused Zuckerberg of making the donations—which they dubbed “Zuckerbucks”—to bolster Democratic turnout in battleground states, which Zuckerberg and election officials in both parties deny. In 2022, Baker said the couple wouldn’t make such donations in the future because it was a one-time pandemic-related move.

In a post this past July on his social-media platform Truth Social, Trump wrote: “All I can say is that if I’m elected President, we will pursue Election Fraudsters at levels never seen before, and they will be sent to prison for long periods of time. We already know who you are. DON’T DO IT! ZUCKERBUCKS, be careful!”

In a coffee-table book released this fall—which had gone to press earlier in the year—Trump included a picture of an Oval Office meeting with Zuckerberg and called for the CEO to “spend the rest of his life in prison” if he tried to rig the 2024 election against him, referring to the election-infrastructure donations from 2020.

Publicly, their relationship appeared to improve. In July, Zuckerberg praised Trump’s response to an assassination attempt—in which he raised his fist and chanted “fight, fight fight”—as “one of the most badass things I’ve ever seen in my life.” The two men spoke days after the shooting, and in October, Trump told a Barstool Sports podcast that he likes Zuckerberg “much better now,” adding, “I actually believe he’s staying out of the election, which is nice.”

In recent months, Zuckerberg has shown more willingness to criticize Democrats and praise Republicans. In August, he said in a letter to the Republican chairman of the House Judiciary Committee that it was improper for the Biden administration to have pressured Facebook to censor Covid-related content in 2021, vowing to reject any such future efforts. He also said he wouldn’t repeat his 2020 election-infrastructure donations because: “My goal is to be neutral and not play a role one way or another—or to even appear to be playing a role.”

Privately, Zuckerberg has told other business leaders that he is optimistic about a Trump presidency, according to some of the people.

After Trump’s election victory in November, Zuckerberg congratulated Trump in a social-media post and said he was looking forward to working with the president-elect.

Zuckerberg has also had arguments with Elon Musk , who ranks as one of Trump’s closest advisers and was a top financial backer during the presidential election. Their feud culminated in a tentative agreement last year to duke it out in a cage match, which never happened.

Trump’s nominees for various positions signal that his administration will be tough on Big Tech, specifically social-media companies, which many Republicans claim have censored conservative voices.

On Tuesday, Trump nominated Andrew Ferguson to be commissioner at the Federal Trade Commission, the regulatory agency that has antitrust oversight of Meta. “At the FTC, we will end Big Tech’s vendetta against competition and free speech,” Ferguson said in a post on X after the nomination.

Write to Dana Mattioli at dana.mattioli@wsj.com and Rebecca Ballhaus at rebecca.ballhaus@wsj.com