Jens Stoltenberg, left, NATO’s secretary general, meets with President Trump on Thursday at the White House. (Andrew Harrer/Bloomberg)

NATO Secretary General Jens Stoltenberg is trying to hold together the 29-nation military alliance at a time of increased internal tensions.

Washington is at odds with European allies over its withdrawal from the Iran nuclear accord. The Trump administration is also considering sanctioning a fellow NATO member, Turkey, for buying Russian air defenses and continues to chastise other NATO countries for spending too little on defense.

President Trump rankled Europe by calling NATO obsolete before entering the White House, but he later pledged support for the military alliance so long as its members agreed to fight terrorism and pay their fair share.

At a White House meeting with Trump on Thursday, Stoltenberg thanked him publicly for emphasizing defense spending. NATO expects that eight countries will spend more than 2 percent of their gross domestic product on defense this year, up from three countries in 2014, when the Obama administration pushed the alliance to set that goal.

“Do you give me credit for that?” Trump asked Stoltenberg in front of the cameras.

“You have helped to do that because your leadership has been important and it has had a real impact,” the NATO secretary general replied diplomatically.

Later, in an interview, Stoltenberg expressed optimism that spending would continue to increase after years of decline. But at the same time, he said he was worried that disunity within the alliance was also on the rise.

“It concerns me, of course, that there are disagreements, differences, between NATO allies on important issues,” Stoltenberg said. “We see that on the Iran nuclear deal. We see it on trade issues. We see it on climate change.”

He acknowledged there have been deep divides in the past, dating to the Suez Crisis in 1956, which pitted the United States against Britain and France. In 2003, he recalled, most of the allies sharply opposed the U.S. invasion of Iraq. 

“For me, as secretary general of NATO, the main task is to make sure we continue standing together in NATO protecting each other — one for all and all for one — as we have done before when we have disagreed,” Stoltenberg said.

Trump has regularly criticized allies for having trade surpluses with the United States. Germany, where about 35,000 U.S. troops are based, has the fourth-largest surplus among U.S. trading partners, a source of tension between Trump and Chancellor Angela Merkel.

Anger among the allies over Trump’s decision to withdraw from the Iran nuclear accord erupted this week at a news conference by European Council President Donald Tusk. “With friends like that, who needs enemies,” he said of Trump. “But, frankly speaking, Europe should be grateful to President Trump. Because thanks to him, we have got rid of all illusions. He has made us realize that if you need a helping hand, you will find one at the end of your arm.”

Though the divides on trade, climate and the Iran deal have largely been initiated by Trump, another division within the alliance has come from its southern flank.

Turkey’s decision to flout NATO protocol and purchase ­S-400 surface-to-air missile batteries from Russia has incensed many in Washington, leading some U.S. officials to consider sanctioning Turkey under new legislative authorities provided by the 2017 Russian sanctions bill. 

Secretary of State Mike Pompeo pressed Turkey’s foreign minister on the matter in a recent meeting, but the minister publicly called the purchase from Russia a “done deal.” Turkey has expressed willingness to buy additional air defenses from NATO allies.

“The United States have said that there will be sanctions, so this is another example of disagreement between allies,” Stoltenberg said. “I have discussed this both today in Washington, but also when I met with [Turkish] President [Recep Tayyip] Erdogan some weeks ago. So this is something that concerns me.”

Stoltenberg welcomed Turkey’s interest in buying air defenses from NATO allies so they can be integrated into the alliance’s systems. In addition to talking to the United States, Turkey is speaking with a French-Italian manufacturer of air defense systems.

“At least they’re working on that, and hopefully they can succeed,” Stoltenberg said.