When German Chancellor Angela Merkel arrived at the White House in April, President Trump was eager to sell her on a long-shot idea: She should push aside the European Union so the two could strike a trade deal of their own.

Trump laid on the charm when making his pitch, a tactic not usually associated with his chilly public relationship with the long-serving German leader.

“You’re the president of Europe!” Trump teased Merkel, according to people familiar with the meeting. “C’mon, Angela, you know it’s true.”

But Merkel refused, laughing along with Trump while telling him firmly that the road to any deal goes through Brussels and the centralized E.U. trade bloc Trump loathes.

Now six months later, Merkel has announced that she will not run for a fifth term as chancellor and will soon step down as her party’s leader. Her decision after 13 years in power is partly due to the rise of right-wing, anti-immigrant forces similar to those that helped propel Trump’s 2016 victory.

For Trump, having Merkel’s political exit in sight is a kind of vindication.

As April’s Oval Office meeting illustrated, the two have represented competing visions for the future of the trans-Atlantic partnership, with the U.S. president pushing an-every-country-for-itself nationalist approach and the German leader staunchly defending the value of a united Europe and the collective institutions Trump resists.

“This is a huge win for Trump. Germany is the largest economy in Europe, and we’ve seen in Sweden, in Italy, France, in the U.K. with Brexit, how this is building,” said a U.S. official, referring to the rise across Europe of right-wing populism and voter dissatisfaction with economic and immigration policies.

Trump has cast Germany as an economic adversary, flogging Europe’s richest nation as a cheapskate. He has held up the country as a symbol to his mostly white political base of the “disaster” of untrammeled immigration. The U.S. leader has told associates since his first days in office that he thought Merkel was out of her depth.

A new German chancellor, when one is chosen, will test whether Trump’s beef with Germany is more about the country or the woman who has led it.

“He’s always playing to a domestic audience and always needing someone he can set up as an object of grievance. Germany has fit that role,” said Jackson Janes, president emeritus of the American Institute of Contemporary German Studies.

But Merkel herself has also confounded Trump.

His point in April was that Merkel, presiding over the continent’s largest economy and with the most to lose from tariffs the United States was prepared to deploy, should understand the art of a deal.

Trump had been told before the April 27 session that Merkel would not go around the E.U. to consider a side agreement or accommodation with the United States, but he was incredulous, current and former U.S. and German officials said.

“He’s like, ‘You’ve got the best economy! You’re crushing it!’ ” one person said of Trump.

Trump has since told other leaders that Merkel looks weak for not using her economic power to dictate terms to the E.U.

“He’s never understood the enormous respect that she enjoys on the world stage, and which he does not,” Janes said.

How to best deal with Trump has been a constant challenge for European leaders. While French President Emmanuel Macron has at times tried to buddy up to him, Merkel has taken a businesslike approach. She doesn’t offer the over-the-top praise Trump enjoys but has also avoided criticizing him directly.

“In many ways Merkel is the anti-Trump. If you think about their personalities, she is the complete opposite,” said Karen Donfried, president of the German Marshall Fund of the United States.

“But one can ask, ‘does that even matter?’ ” when dealing with Trump, said Donfried, who as President Obama’s principal White House adviser on Europe saw close-up how Obama and Merkel traded advice and confidences in frequent — sometimes weekly — phone calls.

Merkel’s April visit came days after Macron had used backslapping bonhomie to try to persuade Trump to remain in the international nuclear deal with Iran and refrain from hitting Europe with the new tariffs. It didn’t work.

The relationship between Trump and Merkel has grown more comfortable over time, but remains wary and dutiful, said current and former officials from both countries who requested anonymity to discuss details of the two leaders’ interactions.

“On both sides of the Atlantic, there’s been a learning process,” said Peter Beyer, Merkel’s coordinator for transatlantic relations.

Merkel’s first White House visit, in March 2017, was marred by controversy over whether Trump snubbed her by not shaking her hand during an Oval Office photo opportunity.

“They want to have a handshake?” Merkel said to an impassive Trump, as the cameras whirred and photographers called, “Handshake! Handshake!”

In their one-on-one meetings, Merkel has tried to counter Trump’s criticisms by offering evidence of how the relationship between their countries is benefiting the United States.

At that first encounter, Merkel came prepared for Trump’s argument that the trade imbalance between the two countries cannot stand. She told Trump that the trade deficit is partly offset by what she called an “investment deficit,” of heavier German investment in the United States, such as car plants, than the other way around, participants and others familiar with that session said.

“Merkel knew what was coming, and she parried it with a bit of humor,” a former senior U.S. official familiar with the meeting said. “She said, ‘it appears we both have a deficit. These are two deficits we can work on together.”

Although the official said her approach took the edge off the meeting, Merkel’s argument seemed to have little effect on Trump.

Trump takes credit for prodding more NATO nations, including Germany, to step up their defense spending toward a goal of 2 percent of GDP. Trump frequently misstates the way the transatlantic alliance is funded, and has suggested that the percentage should be double for Germany.

“He is unbelievably blunt with her. Basically she walks in and he says, ‘your planes don’t fly, your ships don’t sail, your submarines don’t submerge,” an outside adviser to the White House knowledgeable about the Oval Office in April meeting said. “He said, ‘you’re giving more to Russia, while I’ve done far more than you.’ ”

Trump has also complained about the cost of U.S. bases and defense commitments in Germany, which the former top U.S. Army general in Europe said reflects a fundamental misunderstanding on Trump’s part.

“When you talk about 2 percent, and then almost arbitrarily say for Germany it should be 4 percent, and when you characterize it as ‘30,000 American forces over there protecting Germans,’ that’s a completely inaccurate explanation,” said retired Lt. Gen. Frederick B. Hodges III.

The United States uses those forces and its extensive bases in Germany to launch operations and keep watch on America’s behalf throughout the Middle East, Africa, Russia and Europe, said Hodges, now based in Germany with the Center for European Policy Analysis.

Trump has lately shifted criticism of Germany to its purchase of Russian natural gas, and a pipeline project known as Nord Stream 2.

The German government has pursued the 800-mile-long, planned pipeline beneath the Baltic Sea for years, over criticism from the United States.

“Germany, as far as I’m concerned, is captive to Russia because it’s getting so much of its energy from Russia,” Trump told NATO Secretary General Jens Stoltenberg in July. “We have to talk about the billions and billions of dollars that’s being paid to the country we’re supposed to be protecting you against.”

Diplomats had been frustrated that both the Obama administration and then, at first, the Trump administration, did not make a bigger issue of the pipeline, one former senior official said.

“Finally, Trump speaks on Nord Stream 2, and great,” the former official said. “But he says the most humiliating thing possible to Chancellor Merkel as a former East German, that Germany is a vassal state to Russia. Even when he takes the right side to an issue, his approach is so bullying and harsh.”

While Trump has eagerly criticized Merkel in public and private, he’s also grown annoyed at the perception that his relationship with the German chancellor is poor. He has, at times, sought ways to portray it in a more positive light.

He invited Merkel and her delegation on an impromptu tour of the private White House living quarters at the close of their April visit. Merkel’s top aides, already waiting outside, had to scramble back inside the East Wing.

“It was a spontaneous, off-protocol idea by the president,” Beyer said. “He wanted to make the chancellor feel comfortable — to show that he’s a nice guy.”

Trump and Merkel will probably next see each other in late November at the Group of 20 gathering in Argentina. By then, Trump may have imposed new tariffs targeting German cars.

Merkel, a scientist by training who has spent her career dueling with — and often outwitting — alpha-male rivals, has repeatedly pressed her case to Trump that the tariffs would be mutually destructive. But she also believes that to plead for a reprieve would be counterproductive.

“She understands his way of doing politics as that of a businessman, and a dealmaker,” Beyer said. “He builds up a lot of pressure. And he smells weakness.”

For Trump, the weakness he thinks he detected in Merkel dates to 2015 and Germany’s decision to admit a tide of asylum seekers from Syria and elsewhere. Although Merkel was hailed as “the conscience of Europe,” the admissions policy also stoked anger and resentment among some Germans.

In 2013, as he began preparing a potential presidential bid, Trump had tweeted admiration for Merkel. As the refu­gee crisis in Europe unfolded two years later, Trump told supporters that he would not repeat Merkel’s mistakes.

“The president in his world view believed, and probably still does believe, that Merkel’s decision to receive a million refugees . . . was politically a huge mistake, if not a fatal mistake,” a former senior U.S. official said.

Trump was “sort of obsessed” with Merkel and the refu­gee issue in his first months in office, the official said, and raised it during the first meeting he held with a foreign leader, with British Prime Minister Theresa May.

“He had asked Theresa May what she thought of Merkel, and Theresa May had an idea of where the president was going with this. She said, ‘Well, you know, I consider her to be the most capable politician on the European continent.’ And the president said, ‘Really?!’ ”

Trump was further shocked to hear May confidently predict that Merkel would win a fourth term as chancellor.

“He said, ‘How can that be? She’s facing a revolt within Germany because of these immigration policies, because of soaring crime rates,’ ” the former senior official said. “May said she thought Merkel was up to the challenge.”

Merkel did win that fourth term in elections a year ago, although tortuous negotiations to produce a governing coalition had only concluded weeks before Merkel visited the White House in April. The political fault lines have since spread, leading to embarrassing losses for Merkel’s party and her centrist governing principle. It is not clear that she will serve out all of her fourth term, which would run until 2021.

“The time has come to open a new chapter,” she said Monday.

Witte reported from Berlin.