NEW YORK – The former leader of the International Monetary Fund was released from a New York City jail late Friday afternoon after spending nearly a week behind bars on charges of trying to rape a hotel maid.

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

The onetime 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 ran into problems, and he instead will be housed temporarily in lower Manhattan.

Defense lawyer William W. Taylor said outside court Friday that neighbors in the building where he was initially to stay complained about the media attention, and that Strauss-Kahn decided to go elsewhere out of respect for them.

At least one armed guard will be watching him at all times, and he’ll have to wear an electronic monitoring bracelet on his ankle. His apartment’s exterior doors will be outfitted with alarms and video cameras under the terms of the judge’s order.

He won’t be able to leave his temporary housing at all. Once he’s settled somewhere permanent, he’ll be allowed to leave only for court dates, meetings with his attorneys, doctor’s appointments and weekly religious services, and he’ll have to tell prosecutors where he’s going at least six hours in advance.

As for visiting him, no more than four people — not counting relatives — can stop by at any given time, and they’ll be searched for weapons and have their names logged, according to a document the security company prepared for the court.

Strauss-Kahn, 62, has been jailed since Sunday. He is accused of attacking a 32-year-old housekeeper Saturday in his $3,000-a-night hotel suite at the Sofitel hotel near Times Square. The West African immigrant told police he chased her down a hall in the suite, forced her to perform oral sex and tried to remove her stockings.

Strauss-Kahn resigned his post at the IMF on 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.