Marianne Ny said his arrest warrant was being revoked as it was impossible to serve him notice of his alleged crimes.
Mr Assange, 45, has lived in the Ecuadorean embassy in London since 2012, fearing extradition to Sweden would lead to extradition to the US.
Police in London said they would still be obliged to arrest him if he left.
The Metropolitan Police Service (MPS) said Mr Assange still faced the lesser charge of failing to surrender to a court, an offence punishable by up to a year in prison or a fine.
But the UK has not commented on whether it has received an extradition request from the US, where Mr Assange could face trial over the leaking of hundreds of thousands of secret US military and diplomatic documents.
Mr Assange's Swedish lawyer, Per Samuelson, said the prosecutor's decision on Friday represented "a total victory" for his client.
The plaintiff in the rape case was "shocked" by the decision, her lawyer said, and maintained her accusations against Mr Assange, Agence France-Presse reported.
'Focus on UK'
At a press briefing on Friday, Ms Ny said that by remaining in the embassy in London Mr Assange had evaded the exercise of the European Arrest Warrant (EAW) that would have seen him extradited to Sweden.
She said: "According to Swedish legislation, a criminal investigation is to be conducted as quickly as possible. In order to proceed with the case, Julian Assange would have to be formally notified of the criminal suspicions against him.
"We cannot expect to receive assistance from Ecuador regarding this. Therefore the investigation is discontinued."
But she added: "If he were to return to Sweden before the statute of limitation on this case expires in August 2020, the preliminary investigation could be resumed."
She said it was "regrettable we have not been able to carry out the investigation", and added: "We are not making any pronouncement about guilt."
The rape allegation followed a Wikileaks conference in Stockholm in 2012. Mr Assange always denied the allegations against him, saying sex was consensual.
He also said the case was politically motivated, as it followed massive Wikileaks dumps of secret US military reports that year.
After the news was announced on Friday, Wikileaks tweeted that the "focus now moves to the UK".
The MPS issued a statement saying that its actions had been based on a response to a "European Arrest Warrant for an extremely serious offence".
It went on: "Now that the situation has changed and the Swedish authorities have discontinued their investigation into that matter, Mr Assange remains wanted for a much less serious offence. The MPS will provide a level of resourcing which is proportionate to that offence."
The MPS said it would "not comment further on the operational plan".
Last month, Mr Samuelson filed a new motion calling for his client's arrest warrant to be lifted.
He cited a comment by new US Attorney General Jeff Sessions that the arrest of Mr Assange would be "a priority".
Mr Samuelsson told Agence France-Presse: "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."