NEW YORK — The former head of the International Monetary Fund was released from a New York City jail late this afternoon after spending nearly a week incarcerated on charges accusing him of trying to rape a hotel chambermaid.

Dominique Strauss-Kahn was released from the city Department of Correction custody shortly after 5 p.m. and was handed over to the security firm managing his house arrest.

The one-time French presidential candidate posted $1 million cash and $5 million bond Friday, and a judge signed off on an order clearing him to be released from the Rikers Island jail.

Strauss-Kahn’s initial housing arrangement hit a snag, and he instead will be housed temporarily in lower Manhattan. Prosecutors said in court today that neighbors in the building where he was initially to stay complained about the media attention and refused him.

Armed guards will watch over him. He will also be monitored electronically.

The 62-year-old Strauss-Kahn has been jailed since Sunday.

He is accused of attacking a 32-year-old housekeeper Saturday in his $3,000-a-night hotel suite. The West African immigrant told police he chased her down a hallway in the suite, forced her to perform oral sex and tried to remove her stockings.

Strauss-Kahn resigned his post at the IMF Wednesday. In his resignation letter, he denied the allegations against him but said he would quit in order to “protect this institution which I have served with honor and devotion” and to “devote all my strength, all my time and all my energy to proving my innocence.”

Prosecutors had argued against his release, citing the violent nature of the alleged offenses and saying his wealth and international connections would make it easy for him to flee.

The defense said the bail restrictions would ensure he stays in New York City.