BANGKOK — Amid monsoon downpours, pro-democracy demonstrators sang and danced at a police barricade in Bangkok on Tuesday, marking the fourth anniversary of an army coup that again plunged Thailand into military rule.

The festive atmosphere, though, was undercut by police broadcasts over loudspeakers warning that the protesters, some of whom had wished to remain anonymous, had been identified through photographs and video footage. Security provisions imposed by the ruling junta have made any political gathering of more than four people illegal. Anyone participating in the demonstration could be considered to have broken the law.

“Many young people are scared to speak out because they are worried about their future,” said Thanawat Prommajak, a youth activist whose voice had grown hoarse from yelling into a microphone. “The military junta wants to crush us.”

Most of the protesters, who were calling for elections to be held this year, were contained at Thammasat University in Bangkok’s old quarter, the site of a massacre of student activists four decades ago. But a breakaway group of dozens tried to march toward Government House, the seat of Thailand’s executive power. The police herded the organizers of that protest cell into vans and shoved away members of the media.