RIO DE JANEIRO (Reuters) - Brazil's government disbursed 2.9 billion reais ($895 million) to cover Olympic security spending by the state of Rio de Janeiro, which declared a state of fiscal emergency just weeks before the sporting event kicks off on Aug. 5.

A presidential measure published on Thursday in the government's Official Gazette confirmed the emergency loan, an effort to guarantee safety with as many as half a million foreign visitors expected in Rio during its worst financial crisis in decades.

The money will also help complete a subway line crucial for transporting visitors from the city center to Olympic venues in the neighborhood of Barra da Tijuca, Rodrigo Vieira, Rio state's secretary for transport, told reporters on Thursday.

Brazil's economic recession, the worst since the 1930s, is stoking crime and straining public finances, leading to threats of police strikes on the eve of the games.

The first Olympics to be held in South America were originally planned to showcase Brazil's ascent as a global power, but will play out instead against a backdrop of recession, political turmoil and concern about an outbreak of the Zika virus.

Security fears were heightened ahead of the Games as parts of a mutilated body washed up on the sands of Copacabana Beach in Rio on Wednesday, just meters from a beach volleyball venue.

On Thursday, Rio police said they arrested two people and confiscated firearms after a shootout in Cantagalo, a favela, or slum, that overlooks the popular, upscale beach neighborhood of Ipanema. No one was injured.

The government is also seeking to step up security at Rio's international airport in the wake of recent attacks in Brussels and Istanbul.

Serious doubts remain that all the infrastructure work will be finished in time.

The state government had originally requested an additional 500 million reais to finish the rail line, but transport secretary Vieira said the extension could now be finished using money from Thursday's loan. The line is expected to be finished just days before the games.

Further complicating preparations is the broader political flux in Brazil, with the Senate likely to take its final vote on the impeachment of suspended President Dilma Rousseff the week after the Games.

Senate President Renan Calheiros had said the vote would come around Aug. 20, the day before the closing ceremony, but on Thursday he changed his forecast to between Aug. 25 and 27.

($1 = 3.24 Brazilian reais)

(Reporting by by Pedro Fonseca, Caio Saad and Stephen Eisenhammer; Editing by Richard Chang)