ISTANBUL—Russian President Vladimir Putin said Moscow will scrap a planned natural-gas pipeline to the European Union in favor of a link to Turkey, bolstering economic ties with a contentious Western ally amid EU opposition to a project that aimed to strengthen the Kremlin’s influence in Southeastern Europe.

Mr. Putin’s comments during a state visit in Ankara are the clearest sign yet that Russia is bowing to EU opposition to the $20 billion South Stream pipeline, billed by Moscow as a way to secure supplies of Russian gas...