UNITED NATIONS/BERLIN (Reuters) - Germany and Saudi Arabia have agreed to end a prolonged diplomatic row that prompted the kingdom to pull its ambassador from Berlin and punish German firms operating in the country.

FILE PHOTO: German Foreign Minister Heiko Maas attends a news conference with his Greek counterpart Nikos Kotzias (not pictured) following their meeting at the Foreign Ministry in Athens, Greece, September 20, 2018. REUTERS/Costas Baltas

The spat was triggered last November when Germany’s foreign minister at the time, Sigmar Gabriel, condemned “adventurism” in the Middle East, in comments that were widely seen as an attack on increasingly assertive Saudi policies, notably in Yemen.

The comments, which aggravated already tense relations caused by a moratorium on German arms exports to Saudi Arabia, led Riyadh to withdraw its ambassador and freeze out German companies, particularly in the lucrative healthcare sector.

Gabriel’s successor Heiko Maas, egged on by German industry, had been working for months to resolve the dispute. Earlier this month, Berlin signed off on the delivery of four artillery positioning systems to Saudi Arabia, a step that officials say accelerated the rapprochement.

Standing alongside his Saudi counterpart Adel al-Jubeir at the United Nations on Tuesday, Maas spoke of “misunderstandings” that had undermined what were otherwise “strong and strategic ties” between the countries, saying “we sincerely regret this”.

“We should have been clearer in our communication and engagement in order to avoid such misunderstandings between Germany and the kingdom,” he said. “We’ll do our best to make this partnership with the kingdom even stronger than before.”

Jubeir said he welcomed Maas’ statement and invited him to the kingdom to intensify their ties. He spoke of a “a new phase of close cooperation in all areas” between Berlin and Riyadh.

Officials told Reuters that the Saudi ambassador, Prince Khalid bin Bandar bin Sultan, son of longtime Saudi ambassador to the United States, Prince Bandar bin Sultan, was expected to return to Berlin soon.

After weeks of delay, the new German ambassador to Saudi Arabia, Joerg Ranau, is now expected to receive his accreditation and take up his position in Riyadh.

“The Gordian knot has been broken,” said Volker Treier, foreign trade chief at the German chambers of commerce and industry (DIHK), who is in Riyadh to celebrate the 40th anniversary of the local chamber.

“The optimism is back. Diplomacy triumphed,” he said. “Everyone we have met here has made clear they want to work closely with us again.”

The dispute hit trade between the countries. German exports to Saudi Arabia fell 5 percent in the first half of 2018. And companies like Siemens Healthineers, Bayer and Boehringer Ingelheim complained that they were being excluded from public healthcare tenders.

In a strongly-worded June letter to Saudi Crown Prince Mohammed bin Salman, European and U.S. pharmaceutical associations warned that the restrictions could hurt Saudi patients and dampen future investment in the kingdom.

The dispute with Germany predates one that erupted between Canada and Saudi Arabia this summer after the Canadian foreign minister, in a tweet, called for the release of human rights activists in Saudi Arabia.

The kingdom responded by expelling the Canadian ambassador, recalling its own envoy, freezing new trade and investment, suspending flights and ordering Saudi students to leave Canada.

Saudi Arabia’s role in the Yemen war, in which Arab forces are fighting Iran-aligned Houthis, remains controversial in Germany.

Chancellor Angela Merkel’s new government went so far as to write into its coalition agreement earlier this year that no arms could be sent to countries involved in the conflict. It is unclear how recent arms deliveries fit with this ban.