Just a few days after a once fringe far-right party came out ahead in last fall’s elections in Italy, President Biden warned that it could be a sign of trouble for democracy.

At an evening political fund-raiser that September, he told donors that China’s president had argued that “democracies can’t be sustained in the 21st century” and then added, “you just saw what’s happened in Italy in that election,” as if it were an indicator.

But as Mr. Biden hosts Prime Minister Giorgia Meloni at the White House on Thursday, the fears of last fall have largely dissipated. Italy’s new leader has emerged as a strong ally in the president’s central foreign policy priority, the war in Ukraine, and he hopes to strengthen his bond with her during a high-profile visit.

“The president has enjoyed working with her,” John F. Kirby, a spokesman for the National Security Council, said on Wednesday. “Certainly on issues of foreign policy, there’s been a lot of overlapping and mutually reinforcing approaches that we’re taking with Italy.” He noted that Italy is sheltering 170,000 Ukrainian refugees and providing security assistance in the fight against Russian invaders.

That was not always a given. Ms. Meloni’s party, Brothers of Italy, traces its roots to the neo-fascist political factions that emerged after World War II. In forming a coalition government after last September’s elections, Ms. Meloni became the first far-right nationalist to lead Italy since Benito Mussolini. To Mr. Biden’s chagrin, she seemed to be an Italian version of former President Donald J. Trump, having addressed the Conservative Political Action Conference in the United States, a group broadly supportive of Mr. Trump.

Like the former president, Ms. Meloni came to office with a long record of skepticism of Western alliances. She once wanted to get rid of the common euro currency. Tough on migration, L.G.B.T.Q. rights and “woke ideology,” she was seen as more aligned with Prime Minister Viktor Orban of Hungary than her counterparts in Germany and France. And while she personally took a hard line on Russia, her junior coalition partners, Matteo Salvini and Silvio Berlusconi, were friendlier toward Moscow.

But Ms. Meloni has shown that she is in charge when it comes to Ukraine. In a speech in March, she said, “The Ukrainian people are defending the values of freedom and democracy on which our civilization is based and the very foundations of international law.” Mr. Berlusconi, who was once so close to President Vladimir V. Putin of Russia that they would drink together, go skiing together and attend extreme fighting competitions together, died last month.

To Washington’s delight, Ms. Meloni has been drawing away from China. She called it a “big mistake” for Italy to have joined China’s Belt and Road initiative, an international infrastructure cooperative that has been a primary means for Beijing to assert influence across the globe. Italy, which takes over next year as chair of the Group of 7, was the only member of the group to participate in China’s initiative, but Ms. Meloni appears poised to withdraw.

Valbona Zeneli, a senior fellow at the Atlantic Council’s Europe Center, said Western leaders misjudged Ms. Meloni after her election.

“Prime Minister Meloni’s actions have clearly demonstrated a values-based commitment to the trans-Atlantic relationship,” she said. “Italy is a strong partner for the U.S. on many issues, from its support for Ukraine and its active role in holding Russia accountable to its pragmatic defense industry cooperation.”

But Mr. Biden and Ms. Meloni are not in line on domestic issues, which could lead to uncomfortable moments for them. Most notably, Ms. Meloni’s government has told Milan’s city government to stop registering both members of same-sex couples who have babies, recognizing only the biological parent. Parliament is considering a bill that would make pursuing children through surrogates, which is already illegal, a “universal crime” for Italians even in countries where it is legal, like the United States.

Mr. Kirby said the president supported human rights around the world but indicated that Mr. Biden would limit his interactions with Ms. Meloni about such issues.

“The Italian people get to decide who their government is,” he said. “It’s a democracy and the president respects that.”