Russia’s top court has ruled that the Telegram messaging app can be forced to provide user data to security services.

The Supreme Court threw out an appeal by Telegram protesting against demands from the Federal Security Service intelligence agency (FSB) to provide access to user data.

Telegram argued that the FSB violated consumer rights when it demanded that social networks provide authorities with encryption keys and chat histories.

Authorities said the app has been used by violent extremists.

Following the court ruling, Russia’s communications regulator ordered Telegram to provide the encryption keys within 15 days.

Telegram could eventually be blocked in Russia if it does not comply.

Telegram lawyer Ramil Akhmetgaliev was quoted by Russian news agencies as saying the company considers it essential to “keep users’ communications secret”.

The Supreme Court ruling is the latest blow to the popular app, which encrypts user communications and has faced pressure from Russian and other authorities in the past.

The FSB said the app was used by a suicide bomber who killed 15 people in St Petersburg last year.

French authorities said it was also used by Islamic State extremists who killed a priest in Normandy.

And Spanish police said this week the man suspected of plotting an IS-inspired attack in Colombia sent suspicious messages on Telegram.

It is unclear whether the ruling could affect data from users outside Russia.

Telegram, based in Britain, was under threat of closure in Russia last year.

Authorities backed off when company founder Pavel Durov agreed to register the company in Russia.

Communications minister Nikolai Nikiforov said there is no reason Telegram should be exempt from rules applied to other messaging apps, according to Russian news agencies.

Russia adopted counter-terrorism amendments in 2016 obliging telecommunications companies to store call logs and data for months.

Mr Durov tweeted: “Threats to block Telegram unless it gives up private data of its users won’t bear fruit. Telegram will stand for freedom and privacy.”