RIO DE JANEIRO — After months of escalating violence in Rio de Janeiro that included television coverage of tourists being chased and beaten by robbers during the famed Carnival festivities, Brazil’s president on Friday ordered the military to take control of public security in the state.

It is the first federal intervention in a state since Brazil’s return to democracy in the 1980s, and it is seen by some as a bid by the president, Michel Temer, to improve his favorability ratings rather than as a measure to tackle crime.

The decree signed by Mr. Temer on Friday afternoon falls short of a full intervention in the state government. While the military will take control of security, Gov. Luiz Fernando Pezão will continue to run the state government of Rio de Janeiro.

“This decision is motivated more by politics than sound public administration,” said Kennedy Alencar, a political commentator and blogger in Brasília, Brazil’s capital. “Now the focus of news will be on the president’s federal intervention to address an issue that concerns the whole country.”