BERLIN — Germany said on Wednesday that it would withdraw its forces from a military base in southern Turkey after the government of President Recep Tayyip Erdogan refused to guarantee visits to forces there by German lawmakers, deepening a rift between the NATO allies.

The decision by the German cabinet to transfer to Jordan the troops, surveillance planes and refueling jets at Incirlik Air Base in Turkey came after Foreign Minister Sigmar Gabriel failed to persuade others in the Turkish government to ensure the visits by German representatives.

The German defense minister, Ursula von der Leyen, said that German surveillance planes were an important part of operations against the Islamic State. Not having them available for two or three months during the move, however, would have more of a symbolic than practical effect — putting two NATO allies publicly at odds rather than working together.

The dispute over access to the troops has brewed for months as relations have deteriorated between Turkey and Germany, home to the largest Turkish diaspora in the world, with three million people of Turkish descent.

The government in Berlin has been critical of Mr. Erdogan, who has steadily expanded his powers since a failed coup in July, incarcerating or firing tens of thousands of people regarded as political opponents.

In March, Mr. Erdogan and his allies accused Germany of using “Nazi practices” to block Turkish officials from campaigning there before a referendum on constitutional changes to expand presidential powers. Berlin maintained outward calm, but it worked behind the scenes to urge the Turkish leader to halt trips to Germany by Turkish ministers that became rallies in support of the referendum.

The visits by Turkish officials stopped and the worst of the Nazi comparisons were not repeated, but even after Mr. Erdogan narrowly won the constitutional changes he sought in the referendum, the tone in Ankara frequently remained raw and dismissive.

In May, Mr. Erdogan said that Turkey would not try to stop Germany from leaving the base, which Turkey provided when it joined the alliance fighting Islamic State militants in late 2014. “If Germany decides to pull out of Incirlik, we might as well say goodbye,” he said.

Those comments came after similarly biting remarks from the Turkish foreign minister, Mevlut Cavusoglu. “If they want to leave, it is up to them,” Mr. Cavusoglu said. “We are not going to beg. They were the ones who wanted to come and we helped them.”

Ms. von der Leyen struck a more conciliatory tone on Wednesday before the cabinet decision, noting that Turkey was still allowing visits to German soldiers serving in a NATO contingent in Konya.

In addition, she said, Germany and NATO are working “well and noiselessly” with Turkey in the Aegean to keep refugees from crossing en masse to Europe, as they did in 2015. The relationship with Turkey, which has been a NATO member since 1952, “is multilayered,” the German defense minister emphasized.

Turkey has never given a concrete explanation for why it would not guarantee the right of lawmakers to visit, or what it found problematic about such visits.

But Germany has been a vocal critic of the jailing of Mr. Erdogan’s opponents. It has refused Turkey’s requests to extradite some of them, and it has offered asylum to thousands of Turks, including journalists, intellectuals, military officers, diplomats and their families.

Germany has also insisted, so far in vain, on the release of two journalists working for German news outlets who have been incarcerated for weeks or months without charges. The Turkish authorities have granted German diplomats very limited access to the detained journalists, Deniz Yucel and Mesale Tolu.

Access for German lawmakers to troops stationed in Incirlik has been severely curtailed in recent months. The German Army serves at the behest of Parliament, and Germans feel it is essential that lawmakers be able to visit the troops and assess whether to extend their deployment.

The last visit occurred in October, after months of wrangling, following a declaration from the German Parliament that declared the 1915 killings of Armenians under Ottoman rule a “genocide,” a term that Turkey rejects.

Ms. von der Leyen said the move to a base in Jordan, which she visited last Friday, would take at least two months. During that time, German surveillance flights in the fight against Islamic State forces will cease, she said.

There was no immediate reaction in Turkey on Wednesday. But Prime Minister Binali Yildirim did not sound concerned in a brief mention of Germany in a speech on Tuesday. “They can do whatever they like,” he said.

shares