Friends and colleagues of a Russian investigative journalist arrested on drugs charges are celebrating after a court unexpectedly defied prosecutors’ recommendations to incarcerate him.

The decision to instead release Ivan Golunov under house arrest is highly unusual for a system that rarely operates in reverse gear. Almost certainly, the move is in response to spirited protests that have broken out following news of the journalist’s detention on Friday. But Saturday’s ruling is also far from the final word on the matter, with police officials and state TV launching a spirited defence of the prosecution.

That a behind-the-scenes battle was developing in government was clear from the unexplained delays that accompanied the start of proceedings in Moscow’s Nikulinsky Court. Mr Golunov appeared in court, inside the bare metal cage designed for defendants only after 8 pm, a full 11 hours later than scheduled.

In emotional scenes, the journalist waved at his colleagues, who shouted messages of support. At one point, he broke down in tears.

“I never thought I would attend my own funeral," he said.

Earlier on Saturday, state investigators formally charged him on drugs offences, alleging that 5.37 grams of cocaine were found in Mr Golunov’s Moscow apartment. The amount was just enough to be considered under a serious drugs charge and a tariff of 10-20 years imprisonment. They had pushed for him to be kept incarcerated while awaiting trial.

Friends and colleagues have described the charges as an outrageous set-up.

In a joint statement, Mr Golunov’s editor and publisher at Meduza, a liberal online publication, said they had no doubt that their journalist was innocent.

“We know Ivan received threats in the last months,” they wrote. “We know in connection to which text, and we can guess from who. We will find out who is behind this and we will make the information public.”

Friends told The Independent that they had never seen Mr Golunov taking drugs.

“His only drug is curiosity,” wrote former colleague Leonid Bershidsky on Twitter. “In Russia that’s against the law.”

One of Russia’s most conscientious investigative journalists, Mr Golunov has a reputation for probing some of the country’s most dangerous fields.

His recent stories have uncovered corruption and malpractice in local government and in the loan shark business. But The Independent understands that he was most likely targeted in relation to his muckraking around Russian funeral services — a particularly corrupt sphere controlled by mafia groups and high-ranking state officials.

On Sunday, it was revealed that the journalist was working on an investigation linking the head of the Moscow division of Russia’s security agency to corrupt funeral service schemes. Meduza has promised to release the investigation shortly.

Mr Golunov's arrest has been accompanied by an an unexpectedly strong show of solidarity from Russia's journalistic community and beyond.

Even usually cautious voices like Vladimir Pozner, a veteran of Soviet and Russian television, criticised his arrest in strong terms.

“The arrest of Ivan Golunov to spit in the face of every Russian journalist,” he said. “I don’t like it when people spit in my face.”

Several stars of state TV added their names to a petition demanding Mr Golunov’s release. But by Sunday morning, state news broadcasters had reverted to a more traditional position, airing a new “documentary” in support of the police investigation. Mr Golunov had, they alleged, been caught pushing drugs in Moscow clubs. He was also drunk when arrested — a statement that was completely incompatible with images of medical reports they broadcast that actually showed the opposite. Later, the channel was forced to apologise.

Mr Golunov lawyers insist that police broke the law at every stage of his detention. For several hours, they say, police denied the journalist his rights to see a lawyer. They refused to test journalist's fingers to indicate if had even touched the drugs assigned to him. They refused to take fingerprints of the bags themselves. And they searched his apartment without witnesses present.

Soon after Mr Golunov’s arrest, police officials published four photographs purporting to show a drugs laboratory in what they said was the journalist’s apartment. Later, a spokesman rolled back those comments, and said only one of the photos was, in fact, taken there. At the same time, the spokesman insisted Mr Golunov had some unstated connection to the drugs laboratory depicted in the other pictures.

There are strong suspicions that Mr Golunov has been beaten while in police custody with the aim of obtaining a confession.

On Saturday afternoon, following two ambulance visits, Mr Golunov was transferred to Hospital no. 71 in the West of the city. An official statement confirmed he had been preliminarily diagnosed with a concussion and fractured ribs.

That statement was later disputed by the hospital’s head doctor, Alexander Myaslakov, who said there was no way of knowing how Mr Golunov had received his injuries.

Only afterwards was it revealed that Doctor Myaslakov might not have been well placed for an objective assessment of his patient. A regular contributor to propaganda talk shows on state TV, Dr Myaslakov was also, it transpired, an official representative for President Vladimir Putin during his last campaign. Eventually, Dr Myaslakov admitted to having “no sympathy” for the journalist. “As is well known, I’m a conservative man (and a Soviet one as well),” he wrote on Instagram.

That statement added to the sense of scandal around Mr Golunov’s detention, with hundreds risking arrest to protest outside police stations and courtrooms.

According to Proyekt, an investigative publication with good sources in government, the unexpectedly strong civil response has created unease among Russia’s leaders. On the one hand, police authorities are pushing the Kremlin hard for a custodial sentence. On another, it is unclear the Kremlin is ready for such a radical turn.

Anton Kobyakov, an advisor to Vladimir Putin, told state news agency TASS that the Kremlin had decided to take the case under special control.

Mr Kobyakov was unusually critical of the police decision to present photographic evidence as if it was taken in Mr Goldunov’s apartment.