Russia's media regulator has ordered Telegram to give the Federal Security Service (FSB) access to users' messaging data within 15 days, prompting a defiant response from the popular app's co-founder.

The Supreme Court on March 20 threw out an appeal by Telegram opposing demands from the FSB to provide encryption keys needed to read users' messaging data.

After the ruling, state media regulator Roskomnadzor said it must comply within 15 days.

State-run news agency TASS quoted Roskomnadzor officials as saying the regulator will ask a court to restrict access to Telegram in Russia if it refuses.

Telegram's co-founder, Pavel Durov, who lives in self-imposed exile abroad, said on Twitter that his company won't provide the FSB with encryption keys.

"Threats to block Telegram unless it gives up private data of its users won't bear fruit. Telegram will stand for freedom and privacy," Durov wrote.

"The company considers the protection of the privacy of the correspondence of users to be its duty," said a lawyer for Telegram, Ramil Akhmetgaliyev.

He said that any move to block the app must be approved by a court.

Further steps in the showdown will be watched for signs of whether the government will seek to crack down on Internet freedoms following President Vladimir Putin's March 18 election to a new six-year term.

Kremlin critics have used social media to spread the word about antigovernment demonstrations and to publicize corruption allegations against Putin, a former FSB chief and Soviet KGB officer, and his allies.

Telegram, which lets people exchange messages, photos, and videos in groups of up to 5,000 people, has attracted more than 100 million users since it was launched by Russian Internet entrepreneur Pavel Durov and his brother in 2013.

It has become an influential forum for news and debate, featuring popular channels run by news sites, journalists, and political analysts.

The Roskomnadzor demand came shortly after the Supreme Court rejected Telegram's complaint against the FSB's 2016 order obliging it to provide encryption keys.

Telegram's lawyers said at the hearing that the FSB order violated the privacy of correspondence. FSB representatives said the agency did not consider information exchanged via messenger apps to be protected by privacy legislation.

A Moscow court in October imposed an 800,000-ruble ($13,800) fine on Telegram for its refusal to provide the FSB with encryption keys.

In 2014, Durov announced that he had left Russia after he was forced to sell his stake in the social network VKontakte under pressure from the authorities.

Durov said in September 2017 that the FSB had notified him that his firm was in violation of counterterrorism laws requiring companies to provide access to encrypted communications they facilitate.

He said at the time that the Russian authorities were pressuring Telegram to comply with controversial legislation known as the Yarovaya laws.

Rights groups call the laws a draconian infringement on privacy that can be used to stifle dissent, and Durov called them unconstitutional.

With reporting by Current Time TV, RFE/RL's Russian Service, AFP, Mediazona, and TASS