Assange, 41, has been in hiding for two months in the Ecuadorean embassy in London, scene of a scuffle between police and his supporters, The New York Times reported.
The decision to grant him asylum was announced by Ecuadorean Foreign Minister Ricardo Patino during a news conference in Quito, the South American country's capital. He said he hoped Britain would allow Assange to leave the embassy in London for Ecuador.
Britain so far has refused, saying it is legally obligated to extradite Assange to Sweden, where he is wanted for questioning about allegations of sexual misconduct, which Assange has denied.
Patino said his government reached its decision after British and U.S. officials refused to guarantee that if Assange were extradited to Sweden, he would not then be sent to the United States to face other charges. His whistle-blowing Web site has published millions of pages of sensitive documents and communications related to the wars in Afghanistan and Iran and diplomacy, and Assange and his friends say he fears he would be charged with crimes in the United States for the 2010 release of the material.
Assange arrived at the Ecuadorian Embassy June 19. British police officers stood guard outside the embassy Thursday.
Patino told reporters in Quito Wednesday his country "received from the United Kingdom an explicit threat in writing that they could assault our embassy in London if Ecuador does not hand over Julian Assange."
"We are not a British colony," he said.
"The move announced in the official British statement, if it happens, would be interpreted by Ecuador as an unfriendly, hostile and intolerable act, as well as an attack on our sovereignty, which would force us to respond in the strongest diplomatic way," Patino told reporters.
"This is a clear breach of international law and the protocols set out in the Vienna Convention," the Ecuadorian Embassy said on its Web site.
The 1961 Vienna Convention on Diplomatic Relations defines a framework for diplomatic relations between independent countries. It says a host country may not enter the premises of an embassy without the represented country's permission.
The BBC reported Wednesday British officials raised the possibility of revoking the embassy's diplomatic immunity, allowing British officials to enter. In its letter to Quito, Britain cited the 1987 Diplomatic and Consular Premises Act as letting it "take actions in order to arrest Mr. Assange in the current premises of the Embassy," the letter Patino showed reporters said.
Shots fired in Canadian Parliament building
Russian economy no longer growing