But British police said they would still arrest Assange if he tried to leave the embassy, saying he had breached the terms of his bail by refusing to turn himself in when an arrest warrant was issued in 2012.
Today was the deadline for the public prosecutor's office to either renew the pan-European arrest warrant or lift it.
"Director of Public Prosecution, Marianne Ny, has today decided to discontinue the investigation regarding suspected rape by Julian Assange," the prosecutor's office said in a statement.
A lawyer on Assange's legal team, Per Samuelsson, told Swedish radio the decision was "a total victory", saying that Assange was "of course happy and relieved".
More From This Section
Samuelsson also said that the decision meant Assange "is free to leave the embassy whenever he wants", though he later told the TT news agency that he did not know when Assange might leave.
"What I do know is that Sweden does not stop him from doing it. Sweden is out of the game," he said.
Another lawyer, Christophe Marchand, told AFP that "We have been waiting a long time for this decision".
Ny and Chief Prosecutor Ingrid Isgren were briefing reporters on the decision in Stockholm.
The 45-year-old Australian has always denied the 2010 rape allegations, which he feared would see him extradited to the United States and tried over the leaking of hundreds of thousands of secret US military and diplomatic documents.
He has been living at the Ecuadoran embassy in London since 2012, and the British police have said they will arrest Assange as soon as he walks out of the embassy because he has broken his conditions for bail -- a relatively minor offence under British law -- by failing to surrender on June 29, 2012 for extradition to Sweden.
Assange's Swedish lawyer last month filed a new motion demanding that the arrest warrant be lifted after US Attorney General Jeff Sessions said in April that arresting Assange would be "a priority".
"This implies that we can now demonstrate that the US has a will to take action... This is why we ask for the arrest warrant to be cancelled so that Julian Assange can fly to Ecuador and enjoy his political asylum," lawyer Per Samuelsson told AFP at the time.
She accused him of having sex with her as she slept without using a condom despite repeatedly having denied him unprotected sex.
"I am entirely innocent," Assange wrote in a 19-page testimony released in December 2016.
He argues that the sex was consensual and has denounced the accusations as "politically motived".
The investigation had suffered from multiple procedural complications since it began.
The statute of limitations on the rape allegation expires in August 2020.
"It is extremely worrying that six months after the hearing at the Embassy of Ecuador in the United Kingdom, the Swedish prosecutor's office has not yet decided on the judicial situation of Julian Assange," the Ecuadoran Foreign Ministry said in the letter seen by AFP.