Morocco and Israel agreed Thursday to establish diplomatic relations in a deal brokered by the United States, making the North African nation the fourth Arab-majority country in recent months to say it would normalize ties with Israel.

The agreement with Morocco had been anticipated for months, but was held up by Moroccan demands that the United States recognize its sovereignty over a disputed border region, U.S. and other officials familiar with the discussions said.

That logjam broke this month, as President Trump’s tenure nears its end. No other Western democracy has backed Moroccan sovereignty over the Western Sahara region, and Trump’s turnabout ends more than 40 years of official neutrality.

Sen. James M. Inhofe (R-Okla.), a Trump ally and powerful chairman of the Senate Armed Services Committee, has championed the cause of Algerian-backed separatists in that region for years.

“He could have made this deal without trading away the rights of this voiceless people,” Inhofe said on the Senate floor, referring to Trump.

Trump’s decision came a week after he had criticized Inhofe for refusing to hold up the annual defense spending bill over Trump’s demand that it be used to repeal a federal law granting liability protection to technology companies.

Trump has waged a fight with technology companies such as Twitter that have started to crack down on right-wing misinformation online.

“I will VETO!” Trump tweeted on Dec. 3.

Inhofe’s support for the separatists had made Trump reluctant to act earlier, said a U.S. official and a foreign official with knowledge of the negotiations. They spoke on the condition of anonymity to discuss sensitive diplomacy.

“In the conversations before the elections with the U.S. administration, they often said that the president would have liked to move forward and recognize the full sovereignty of the Kingdom of Morocco over the entire Moroccan Sahara, but that they couldn’t move forward because they didn’t want to lose the support of the senator from Oklahoma who was against that step,” said the foreign official.

“However, in recent time, we heard that the situation had changed and it opened new opportunities for moving conversations forward.”

In an interview, Inhofe said he was blindsided by Trump’s action. Inhofe said the White House did not threaten retaliation or link the two issues.

“I found out when you found out. And so, I don’t think that’s true,” Inhofe said of whether the policy shift was connected to the defense bill. “I think, his staff has been trying to get him to do this for a long period of time. And he hasn’t done it.”

Trump is “running, arguably, out of time,” and wants to secure his foreign policy victories, Inhofe said.

“So I think that’s the driving force, as opposed to trying to get at me.”

Trump announced the diplomatic deal and the policy shift in tweets.

Winning U.S. recognition of Moroccan sovereignty over the region has been a chief policy goal for Morocco, which is among the most populous Arab states and a key prize among countries the Trump administration has courted.

“This is something that’s been talked about for a long time but something that seemed inevitable at this point and something that we think advances the region and helps bring more clarity to where things are going,” Jared Kushner, Trump’s son-in-law and Middle East negotiator, told reporters about the Western Sahara shift.

Shortly after the deal was announced, two congressional aides said the Trump administration is expected to ask for a go-ahead to sell additional U.S.-made weapons to Morocco. The aides, who spoke on the condition of anonymity because they were not authorized to discuss the matter on the record, said the sale is expected to include military drones.

The administration is seeking an expedited congressional review of the sale with an aim to get it approved before the close of the congressional session and the end of the Trump administration, in January, the aides said.

This week, senators failed to block a similar arms sale that the administration announced for the United Arab Emirates in the wake of that country’s signing a peace deal with Israel that had been announced in August. The $23 billion sale will make the UAE the first Arab country to acquire F-35 fighter jets, alongside Reaper drones, missiles and munitions.

The piecemeal diplomatic and economic agreements between Israel and Arab neighbors have become a hallmark of Trump’s unorthodox approach to foreign affairs. They are likely to stand as his main legacy in the Middle East, where he once hoped to broker what he called the “ultimate deal” settling decades of enmity between Israel and its neighbors.

President-elect Joe Biden has welcomed the initiative.

Like the agreements between Israel and the UAE, Bahrain and Sudan, the Moroccan accord ­bypasses the Palestinians, who want a comprehensive peace deal with Israel on terms Israel has rejected.

Palestinian leaders have branded Arab states as traitors for making individual agreements, although the UAE had conditioned its deal on Israel’s shelving potential plans to annex parts of the West Bank that Palestinians claim for a future state.

Trump spoke by phone Thursday with Morocco’s King Mohammed VI to secure the agreement, under which Morocco and Israel will establish full diplomatic ties and official contacts, as well as direct flights between the two countries.

Trump affirmed the strength of U.S.-Moroccan ties, which date to 1777, according to a summary of the conversation released by the White House.

Also Thursday, Morocco’s official Ewa news agency published an open letter to Biden that accused the separatists of violating a cease-fire and maintaining ties to regional armed groups.

The separatist movement, often known as the Polisario, “jeopardizes peace and security in the whole region, rendering it a breeding ground for terrorism,” the letter said.

The matter is not settled, Inhofe said. He noted that international organizations including the United Nations and the African Union do not recognize Moroccan sovereignty and should not budge.

“I urge these organizations to stand strong to support Western Sahara’s right to self-determination and am confident the U.S. will be able to return to the policy we’ve held since 1966,” Inhofe said.

A communique from Morocco’s royal cabinet on the agreement said official contacts and diplomatic relations with Israel would come as soon as possible. The agreement announced in Washington contains no deadline for the opening of embassies, but Kushner said it would happen soon.

The kingdom said it plans economic and technological cooperation and would work to reopen liaison offices in the two countries that operated for several years until being closed in 2002.

Israeli Prime Minister Benjamin Netanyahu thanked Trump and Mohammed for what Netanyahu called a “historic peace.”

“The people of Morocco and the Jewish people have had a warm relationship in the modern period. Everybody knows the tremendous friendship shown by the kings of Morocco and the people of Morocco to the Jewish community there,” Netanyahu said in a statement issued by his office.

Morocco has an ancient Jewish community, and Mohammed’s grandfather is credited with saving Jewish lives during the Holocaust.

“This will be a very warm peace. Peace has never — the light of peace on this Hanukkah day has never — shone brighter than today in the Middle East,” Netanyahu said.

The Israeli and Moroccan ambassadors to the United Nations spoke by phone on Thursday, the Israeli U.N. mission announced.

The deal leaves unresolved whether Trump can deliver a deal between Israel and Saudi Arabia before he leaves office next month. Trump has predicted such an agreement will come under his auspices, but time is running out. Trump denies he lost the November election.

Miriam Berger in Washington, Shira Rubin in Tel Aviv and Sudarsan Raghavan in Cairo contributed to this report.