TEHRAN — Iran blocked Telegram, the most popular messaging app in the country, on Tuesday, claiming the service used by 40 million Iranians endangers national security.

It was just the latest in a series of moves by the Iranian authorities to limit use of the app, part of a tug of war between hard-liners and President Hassan Rouhani, who has long campaigned for more freedom on social media.

The hard-liners complain that Telegram poses dangers because Iran’s censors have no control over it. In a statement posted on the news website Mizan, which is associated with the country’s conservative judiciary, a prosecutor accused Telegram of supporting terrorists and other hostile groups.

The minister of information and communication technology, Mohammad Javad Azari Jahromi, at 35 the youngest member of Mr. Rouhani’s cabinet, said on Twitter that trying to stop technology was pointless.