MOSCOW — President Vladimir V. Putin of Russia called President Trump on Sunday to thank him for a tip from American intelligence agencies that helped prevent a terrorist attack in Russia, the Kremlin said in a statement.

The announcement offered no details about what information the United States had passed along.

But the Federal Security Service, the main successor agency to the K.G.B., told Russian media it had detained two suspects preparing an attack on a crowded location in the northern city of St. Petersburg on New Year’s Eve.

The two countries’ spy agencies typically view one another as adversaries, for example backing opposing sides in wars in Ukraine and, until earlier this year, in Syria.

But when it comes to counterterrorism, they cooperate.

Two years ago, Mr. Putin thanked Mr. Trump for information about another planned attack, also in St. Petersburg. And on Sunday, the Kremlin statement said Mr. Putin had again thanked Mr. Trump for “information transmitted through the channels of U.S. special services.”