The leftist leader never mentioned Gates by name. But most of the speech, and all of the applause lines, were clearly directed at the Pentagon chief and former head of the CIA.
Bolivia is more democratic and representative than the United States, Morales said, and democracy would improve in the entire region if the United States stopped interfering.
Bolivia -- a country with a history of political instability and coups -- receives $70 million in U.S. aid annually, much of it for popular nutrition and health programs.
In his opening statement, Morales mentioned the spread of Iranian and Russian business and other ties in Latin America, and said it is not the U.S. place to complain.
"Bolivia under my government will have an agreement, an alliance, to anyone in the world," Morales said. "Nobody will forbid us," he said to applause.
Last month Bolivia said it is interested in buying Iranian-made airplanes and helicopters for military training and transportation.
Bolivia also wants to team up with Iran to build a nuclear power plant and establish a joint development bank.
Gates didn't seem fazed by the one-hour monologue. A day earlier he had warned that countries doing business with Iran should remember that Iran is under international sanctions over its nuclear program. He also questioned whether Iran has the technical capability to help another nations develop civilian nuclear power.
"As a sovereign state Bolivia obviously can have relationships with any country in the world that it wishes to," Gates said Sunday. "I think Bolivia needs to be mindful of the number of United Nations Security Council resolutions that have been passed with respect to Iran's behavior."
Morales, an ethnic Aymara and former coca-growers' union leader, was first elected in December 2005 and recently declared that he intends to run again in 2014.
Morales' government has also picked fights recently with the Catholic Church and with the Bolivian press.
In response to Catholic Bishops' expressions of concern about the loss of democracy in Bolivia, Morales' interior minister accused the Church of being an anti-Democratic force in the world.
The Bolivian press, meanwhile, united in opposition to a government anti-racism law that the newspapers argue establishes the framework for press censorship.
Morales' closest ally is the fiercely anti-U.S. leader of Venezuela, Hugo Chávez.
The Associated Press contributed to this report.