CAIRO — At least 25 soccer fans died on Sunday in a confrontation with the police at the gates of a stadium, morgue officials said, in the latest flash of violence to confront the military-backed government as it struggles to restore security 18 months after coming to power.

The death toll was expected to rise.

The hard-core fans known as Ultras are proud of their long history of battling the police and they often formed the front lines of the violent protests that followed the Arab Spring revolt here four years ago.

In February 2012, a brawl between rival groups of fans at a match in the city of Port Said killed at least 70 people. The Egyptian authorities became so worried about their inability to control the crowds that for the past three years they have banned fans from soccer games, forcing teams to play in virtually empty stadiums.

The violence on Sunday was set off in part by an attempt to begin loosening those restrictions, allowing the sale of just 5,000 tickets to the public, according to reports in the official state news media.