By Carlotta Gall, New York Times

ISTANBUL — Prime Minister Alexis Tsipras of Greece is to arrive in Turkey on Tuesday for a two-day visit, his first as prime minister, amid signs of a growing understanding between him and President Recep Tayyip Erdogan of Turkey.

Bilateral relations between the countries remain fraught with disagreements old and new, but their leaders appear to have a pragmatic sense of each other and their political needs.

The visit follows a groundbreaking visit by Mr. Erdogan to Greece in December 2017, the first by a Turkish president in 65 years. Mr. Erdogan, who was at the time heading into an important election campaign at home, stunned his hosts by calling for a revision of the treaty that defines the border between the two countries, and by raising concerns about the Muslim Turkish minority in Greece.

The two leaders met again last July, on the on the sidelines of the NATO summit meeting, after Mr. Erdogan’s election to a new powerful presidency. Now it is Mr. Tsipras who faces an election, and he is expected to use the trip to burnish his own image.

Commentators on both sides expect no breakthrough agreements from the visit, but Mr. Tsipras’s planned visit to a famed Greek Orthodox theological seminary, which the Turkish government forced to close in 1971, is making headlines at home.

Mr. Tsipras, the first sitting Greek prime minister to go to Turkey in almost six years, is to meet on Tuesday with Mr. Erdogan in the Turkish capital, Ankara, and then travel to Istanbul on Wednesday. He plans to attend an Orthodox Mass and meet Ecumenical Patriarch Bartholomew I, the leader of Orthodox Christianity, on the island of Heybeliada in the Sea of Marmara, near Istanbul.

His visit to the Halki seminary on the island would be the first by a serving Greek prime minister in 90 years. Once the fount of Greek learning in the region, it produced both lay and religious leaders, including Patriarch Bartholomew, before Turkey shut it down.

Mr. Tsipras’s visit has raised hopes among Greeks and the small Greek minority in Turkey that he can bolster their long-running campaign to reopen the seminary.

Much of the modern friction between the two countries dates from a century ago, when they went to war as the Ottoman Empire collapsed, and more than a million people were forced to relocate from one country to the other. But the antagonism was already centuries old.

The two nations, both NATO members, still have many longstanding disagreements, including conflicts over territory and energy rights in the Aegean Sea, as well as the decades-old dispute over northern Cyprus. Turkey is also seeking the extradition of eight Turkish soldiers accused by Mr. Erdogan’s government of backing the failed coup of 2016. The soldiers fled to Greece and requested asylum.

But the countries have also cooperated, sometimes fitfully, in recent years on development of a natural gas pipeline through both countries, and on stemming the flow of migrants into Europe.

Both nations could benefit from improved economic ties. Greece has been grappling with years of austerity and indebtedness, and Turkey has suffered a dramatic currency collapse and double digit inflation.

“The conditions must be created in Greek-Turkish relations for historic steps to take place,” Mr. Tsipras told Anadolu, the semiofficial Turkish news agency, before his visit.

Mr. Tsipras said that his relationship with Mr. Erdogan had been “challenged in very difficult moments,” the news agency reported. “But it allowed us to consolidate channels of communication on many levels, to overcome obstacles and to be able, today, to speak of a positive agenda.”

Turkey’s presidential spokesman, Ibrahim Kalin, welcomed the visit and commended Mr. Tsipras’s attitude toward the relationship.

“The approach is positive and with good intentions,” Mr. Kalin said at a news briefing on Monday. “We believe the meetings tomorrow will be held under this framework.”