The ruling by the Uppsala District Court does not mean a preliminary investigation in Sweden should be abandoned.
It states Assange would not be extradited and could be questioned in Britain, where he is currently in prison.
In April, the 47-year-old was evicted from the Ecuadorian embassy in London, where he had sought political asylum since 2012.
He was immediately arrested by police on 11 April and is currently serving a 50-week sentence in Britain for breaching bail.
Eva-Marie Persson, Sweden’s deputy director of public prosecutions, said she has not decided whether to appeal against the decision.
“I fully respect the court’s decision,” she added. “The investigation continues with interviews in Sweden and I will also issue a European investigation order in order to interview Assange.
“No date has been set yet. We will constantly review the state of the investigation.”
Assange’s lawyer in Sweden, Per E Samuelsson, said his client would “be happy” to learn he will not be extradited to Sweden.
Last month, Sweden reopened an investigation into the rape allegation against Assange, which he denies.
He is also fighting extradition to the United States, which has accused him of publishing secret documents.