Troops from a Russia-led military alliance arrived in Kazakhstan on Thursday to restore order after protests in the Central Asian country turned violent, with the police reporting that dozens of anti-government demonstrators had been killed and hundreds injured.

The crisis in the oil-rich country marks the biggest challenge yet for the country’s president, Kassym-Jomart Tokayev, in power less than three years, and also threatens to destabilize an already volatile region. Mr. Tokayev requested the Russia-led intervention.

The foreign soldiers were dispatched after the city hall in Almaty, the country’s largest city and former capital, was set ablaze on Wednesday, and the airport was overrun by an angry mob. Violence spread through the night. The police opened fire on the demonstrators, some of them armed, but also accused them of killing 18 law enforcement officers and troops, and leaving 750 injured.

Throughout the day on Thursday, there were reports of continued clashes in Almaty, with the police saying they were “cleansing the city of militants.” Heavy gunfire echoed through the city. People hunkered in their homes posted videos of smoke billowing from buildings around the city.

On Thursday night, the internal affairs ministry said it had regained control of all government buildings in Almaty.

The reports of deaths could not immediately be independently confirmed.

Kazakhstan, the world’s largest landlocked country, has some of the largest oil fields on earth and more than 40 percent of the world’s uranium production. But the average salary in Kazakhstan is the equivalent of $570 a month, according to the government’s statistics, and many are angry at socio-economic disparities, which have been made worse by the pandemic.

The Russian-led effort to quell the unrest, described as a temporary peacekeeping mission by the military alliance, the Collective Security Treaty Organization, will be limited in time and will aim at protecting government buildings and military objects, the group said in a statement.

The group has dispatched about 2,500 troops to Kazakhstan, and that figure could rise, its secretary general told the Russian state news agency RIA Novosti. He would not say if they had been sent only to Almaty, or to other cities, as well.

This is the first time in the history of the alliance, which is Russia’s version of NATO, that its protection clause has been invoked.

Russian state-run outlets posted videos of Russian troops boarding military aircraft and others driving to Kazakhstan in armored vehicles.

Saltanat Azirbek, a police spokeswoman in Almaty, said that dozens of people had been “eliminated” by the authorities when they tried to storm government buildings and the headquarters and district offices of the police, the first widespread fatalities since the protests started.

The authorities reported that in addition to those who had been killed, about a thousand people had been injured and up to 400 had been hospitalized. By Thursday, around 2,000 people had been detained in Almaty, the Kazakh interior ministry said in a statement read out on state television. Two of the members of the security staff that were killed had been beheaded, Almaty’s commandant’s office said in a statement carried by Khabar-24, Kazakhstan’s state news channel. The protesters also surrounded two hospitals in the city, the statement said.

The police warned people living near main government buildings to stay at home.