President Michel Temer compared the violence to "cancer" and said organised criminals had all but seized control of the state.
Rio's governor issued an appeal for help after the annual carnival celebrations were marred by violence.
The army will oversee police and other security services.
Overseeing the operation will be Gen Walter Souza Braga Netto, head of the Eastern Military Command. He was widely praised for his part in co-ordinating security for the 2016 Rio Olympic Games.
What led to the situation?
Signing the decree, Mr Termer said he was taking "extreme measures" because circumstances demanded it.
"The government will give tough and firm answers, taking all necessary measures to eradicate organised crime," he said.
There were chaotic scenes during the famous Rio carnival, with gun fights and looting. Three police officers died in violent clashes.
National TV news bulletins also broadcast footage of gangs surrounding and robbing tourists.
With the security situation apparently spiralling out of control, state governor Luiz Fernando Pezao made a plea to the national government saying military intervention was the only way to tackle the heavily armed gangs.
He apologised to those revellers affected, saying: "We were not ready. There were mistakes in the first days and we reinforced the patrols."
Why has the violence worsened?
Rio's police budget has been slashed in recent years because of a financial crisis. There have been criticisms that police do not even have the money to pay for the petrol in their patrol cars.
Finances in Rio state have been badly hit by a national recession and a slump in oil prices, as well as high levels of corruption.
The financial problems have only emboldened criminal gangs.
Figures from the Rio state government show an 8% increase in killings last year over 2016 and a 26% jump since 2015.
More about: Brazil