Mr Zelaya was taken to an airbase outside the city and rumours swirled over his whereabouts.
The BBC's Stephen Gibbs, in the region, says armoured vehicles were on the streets and troops fired tear gas to disperse the president's supporters outside his home.
Several hours later Mr Zelaya turned up in Costa Rica and said troops had "kidnapped" him in his pyjamas.
He insisted he was still the rightful president and urged Hondurans to resist those who had removed him.
"This was a plot by a very voracious elite, an elite which wants only to keep this country isolated, in an extreme level of poverty," he said.
Later the Honduran Supreme Court said it had ordered the removal of the president, who had been due to leave office next January.
Then Congress produced what it said was Mr Zelaya's letter of resignation, which it voted to accept. The ousted president dismissed the letter as a fake.
Chavez military warning
There was international condemnation of events in Honduras:
Took office in Jan 2006; beat ruling National Party candidate
Has moved Honduras away from its traditional ally the US
Enjoys the support of Venezuela's leftist President, Hugo Chavez
A civil engineer and rancher by profession
• At an emergency meeting in Washington, the Organization of American States said it was a "coup"
• Venezuelan President Hugo Chavez, blamed "the Yankee empire", and threatened military action should the Venezuelan ambassador to Honduras be attacked; President Evo Morales of Bolivia described Mr Zelaya's removal as "an assault on democracy"
• The White House denied any involvement; President Barack Obama urged Honduras to "respect the rule of law" and a State Department official said America recognised Mr Zelaya as the duly elected president
• The European Union called for "a swift return to constitutional normality" in Honduras
The military's dramatic move came after President Zelaya sacked the chief of the army, Gen Romeo Vasquez, on Wednesday for refusing to help him organise the referendum.
A day later, the Honduran Congress approved plans to investigate whether the president should be declared unfit to rule.
In an interview with Spain's El Pais newspaper published on Sunday, Mr Zelaya said a plot to topple him had been thwarted after the US refused to back it.
The Central American country - an impoverished coffee and banana-exporting nation of more than 7 million people - has experienced military coups in the past.
Soldiers overthrew elected presidents in 1963 and again in 1975; the military did not turn the government over to civilians until 1981.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.