A London court has blocked the extradition of Julian Assange to the US to stand trial on criminal charges, on the grounds that the move would put him at risk of suicide.

A judge at Westminster magistrates’ court ruled that Mr Assange should not be sent to the US to face trial on one charge of computer hacking and 17 charges of violating the US’s 1917 Espionage Act relating to one of the biggest leaks of classified material in history.

If found guilty Mr Assange, who has been diagnosed with an autism spectrum disorder, would face up to 175 years in jail. The US government has already indicated that it will appeal.

District Judge Vanessa Baraitser blocked Mr Assange’s extradition on the grounds that he would be held in harsh US prison conditions and “the risk that Mr Assange will commit suicide is a substantial one”.

“I am satisfied that, in these harsh conditions, Mr Assange’s mental health would deteriorate causing him to commit suicide . . . I find that the mental condition of Mr Assange is such that it would be oppressive to extradite him to the United States of America,” the judge ruled.

The US charges stem from WikiLeaks’ publication in 2010 of a huge cache of secret documents passed to him by Chelsea Manning, the former US military intelligence analyst.

The trove, which includes 90,000 activity reports relating to the war in Afghanistan, 400,000 relating to the Iraq war and 250,000 US diplomatic cables, was one of the largest ever leaks of classified material and caused considerable embarrassment to the US government.Washington has accused Mr Assange of putting US intelligence sources at risk by publishing unredacted documents but his defence lawyers have argued that there is no evidence any individual was harmed.

Mr Assange’s legal team had claimed that the WikiLeaks founder’s prosecution under the US Espionage Act set a dangerous precedent for press freedom and criminalised investigative journalism. They argued that he was working as a journalist when he obtained and published the leaked material and should be covered by freedom of speech protections under the European Convention on Human Rights.

They also claimed Mr Assange’s prosecution was politically motivated and was authorised by President Donald Trump as part of his drive to punish whistleblowers and intimidate journalists.

However, District Judge Baraitser rejected these arguments and ruled there was no evidence of hostility by the Trump administration towards Mr Assange. “The defence has not established that Mr Assange has been the target of a politically motivated prosecution,” she ruled.

She also noted that mainstream media organisations had redacted names of informants, unlike WikiLeaks’ “data dump”, and said that free speech arguments “do not comprise a trump card” for individuals such as Mr Assange “to decide the fate of others”.

Marc Raimondi, the acting director of public affairs at the Department of Justice, said: “While we are extremely disappointed in the court’s ultimate decision, we are gratified that the United States prevailed on every point of law raised. In particular, the court rejected all of Mr Assange’s arguments regarding political motivation, political offence, fair trial, and freedom of speech. We will continue to seek Mr Assange’s extradition to the United States.”

In a surprise intervention, Mexican president Andrés Manuel López Obrador, who takes pride in his country’s tradition of offering political asylum, called the ruling “a triumph of justice”.

“I’m going to ask the foreign minister to take the necessary steps to ask the UK government for the possibility for Mr Assange to be freed and for Mexico to offer him political asylum,” he told a news conference.

Mr Assange’s extradition hearing took place in September, but District Judge Baraitser reserved her decision on the case until Monday. The US legal team had to prove that the alleged offences were crimes in the US and UK at the time they were committed, rather than decide the WikiLeaks founder’s innocence or guilt.

The hearing concluded on Monday and Mr Assange remains in Belmarsh prison, a high-security jail in south-east London, until a bail application can be made on Wednesday.