The new pipeline, known as the Turkish Stream, would run under the Black Sea to Turkey and then the Greek border, allowing Russian gas to reach Western markets without using Russia’s existing export pipelines through Eastern Europe.

The pipeline would make it much easier for Russia to cut off gas supplies to neighboring countries like Ukraine without disrupting sales to countries farther west like Italy or Austria. Russia has been trying for years to establish such an export route.

Mr. Putin’s appearance at an international energy conference was his first visit to Turkey since a crisis in relations between the countries after Turkey’s downing of a Russian fighter jet along the border with Syria in November 2015, in which a Russian pilot was killed. President Recep Tayyip Erdogan of Turkey, nominally an ally of the United States in Syria, patched things up with a letter of apology and a trip to St. Petersburg in August.

The two have sought to use their warming relationship both at home and abroad to indicate that they are not politically isolated and remain central players in any Syria solution. They sat next to each other in the front row of the World Energy Congress in Istanbul, laughing together, and later met for bilateral talks.

Both Mr. Putin and Mr. Erdogan have had recent troubles with Washington. The United States broke off cooperation with Moscow over Syria and then accused the Kremlin of war crimes. Mr. Erdogan has been criticized by Washington for using the aftermath of a July coup attempt to introduce a sweeping crackdown against a wide array of critics, going well beyond the coup plotters and their backers.

Turkey and the United States have also been at odds over the Kurds. Mr. Erdogan considers Kurdish militia fights in Syria to be terrorists and a national security threat. Washington relies on the Syrian Kurds as its main ground force in the fight against the Islamic State.

Mr. Putin has been far more supportive of the Turkish leader’s behavior since the coup attempt. The Russian president has also long sought to exploit any cracks in NATO, of which Turkey is a member.

Anna V. Glazova, the head of the Asia and Middle East Center at the Russian Institute of Strategic Studies, noted that Mr. Putin could easily have sent a minister to the Istanbul summit meeting.

“This means that he wanted to discuss regional problems with Erdogan face to face,” Ms. Glazova said. “This becomes especially important in the context of Russia’s current tensions with the U.S.”

Mr. Erdogan suggested earlier this month that Turkey would propose ways to revive the cease-fire in Syria that collapsed amid mutual recriminations between Russia and the United States. Ankara would also like both the United States and Russia to support the establishment of a no-fly zone in Syria along the border that would eventually be used as a protected area to settle millions of refugees.

Mr. Erdogan told reporters at a joint news conference on Monday that the two presidents had discussed Turkey’s military operations in Syria and possible cooperation to clear Islamic State fighters from the border.

“Regarding Aleppo, we discussed strategies that could be applied on humanitarian aid, so that the inhabitants who are in a dire situation there can quickly attain peace and calm,” Mr. Erdogan said.

Mr. Putin said that “both Russia and Turkey stand for the earliest cessation of bloodshed in Syria,” and added that “the switch to a political settlement must happen as soon as possible.”

“Together with the Turkish president, we agreed to do everything to support de Mistura’s initiative on the withdrawal of military units, which refuse to lay down their arms, from Aleppo in order to end violence,” he said, referring to Staffan de Mistura, the top United Nations diplomat for the Syrian conflict.

Both Mr. Erdogan and Mr. Putin have said they want to restore robust trade ties, although some differences remain. During the gas-pipeline signing ceremony in Istanbul on Monday, Mr. Putin said ministers and experts would continue to hold bilateral talks on economic and political issues, tourism and culture. Mr. Putin also announced that Russia would lift the ban that was imposed on imports of some Turkish agricultural products after the jet was shot down.

The Turkish Stream gas pipeline is intended to replace a planned pipeline through Bulgaria that the European Union blocked at the outset of the Ukraine crisis. Some European governments and the United States also oppose the Turkish Stream project.

The revived agreement to build the pipeline also includes a common geopolitical sweetener from Russia: a reduction in the price that Gazprom, the Russian natural gas giant, would charge for natural gas sold on Turkey’s domestic market.

The main subject of the gathering was the oil industry. Mr. Putin met on the sidelines with the leaders of various producing states like Venezuela, and said in a speech that Russia was prepared to participate in an agreement on production cuts to shore up the price of oil.

“In the current situation, we believe that freezing or cutting oil production is the sole means to preserve the stability of the energy sector and to speed the rebalancing of the market,” Mr. Putin said at the energy conference.

Despite their newly cordial relations, both Turkey and Russia continue to back opposite sides in the civil war. Russia has used its air force to buttress the rule of President Bashar al-Assad of Syria. Turkey has backed the rebels, within certain limits; it does not want to see Kurdish power expand across Syria’s fragmented north.

While relations were strained, Moscow accused Turkey of turning a blind eye toward terrorists operating in the region, and indeed abetting their operations by buying oil from the Islamic State, a charge Turkish officials denied.

“Russia and Turkey are neighbors, so they will have to either cooperate or compete,” Glazova said. “Today, the fact that both countries have troubles with the U.S. brings them closer to each other.”