The men, who apparently were seeking to leave the island, crashed the gates of the embassy in a stolen bus late Wednesday night.
"Today, at 4:30 a.m., a specialized and unarmed unit carried out the ejection in a planned manner, in keeping with the request and desire of the Mexican government, without the least incident," a government statement said.
The communique added that Mexico's special envoy for the crisis, Gustavo Iruega, the deputy foreign minister for Latin America and the Caribbean, and other Mexican diplomats had repeatedly asked the intruders to leave "as they had no real reason or right to stay there."
Given their refusal, Mexico asked Cuba to eject them from the building "in a way which would avoid any physical harm to the intruders and with the use of minimal force," it added.
It was not known precisely how the men were ejected, but they were seen during the operation walking in an orderly line past an embassy window, accompanied by helmeted Cuban soldiers.
The Cubans crashed through the embassy gates late Wednesday, sparking scenes of chaos and violence in nearby streets between police and other mainly young people who had gathered hoping to enter the building.
The situation was provoked by rumors that Mexico was offering to take in Cubans who wanted to leave the island. Cuba says it arrested 150 people in Wednesday night's melee outside the embassy.
With Cuban police ringing the compound and sealing off the surrounding area since then, a group of Mexican officials went in twice Thursday, apparently trying to negotiate with the men, who wanted to leave the Caribbean island to work abroad.
The case recalled several incidents in recent decades in which asylum-seekers have stormed diplomatic premises in Havana. In 1980, some 10,000 people invaded the Peruvian Embassy, an episode that also was touched off by a bus break-in that killed a Cuban guard.
The 1980 crisis led President Fidel Castro's government to temporarily ease Cuba's strict limitations on emigration, prompting a famous exodus of some 125,000 refugees from the port of Mariel to the United States.
With that and other incidents in mind, both Cuba and Mexico were eager to quickly defuse this week's situation.
Mexico said immediately it was not considering the group asylum-seekers and wanted them to leave its premises, while Cuba insisted they were criminals incited from abroad.
In an earlier communique on Friday morning, Cuba listed penal records of 13 of the 21 as evidence they were "criminals, anti-social elements" who responded to an "invitation to assault the embassy" by an anti-Castro, U.S. government-funded radio station, Radio Marti.
Cuban authorities say Radio Marti maliciously broadcast into Cuba an over-literal version of comments by Mexican Foreign Minister Jorge Castaneda in Florida saying the embassy was "open" to all Cuban citizens.
Hundreds of young Cubans who gathered in nearby streets after hearing rumors Mexico was opening its doors to emigrants tried to follow in the bus' wake but were beaten back by police and chased away in a street-battle.
"The penal record and social characteristics of the rest of those who tried to force their way into the Mexican Embassy without succeeding it, and of whom 150 were arrested, are exactly the same," Cuba's first communique said.
Dissidents - and many young Cubans interviewed at the scene - claim that harsh economic conditions, emigration restrictions, and Castro's authoritarian one-party political system are the root causes for this week's incidents and the desire of so many on the island to leave.
The Cuban Commission for Human Rights and National Reconciliation reported "various hundreds" had been arrested around the embassy Wednesday, and said the 21 who broke in may face severe reprisals if handed over unconditionally.
The standoff was an awkward problem for Cuba and Mexico, traditionally strong allies but whose relationship has been strained recently by the disapproval of President Vicente Fox's government of Cuba's rights' and democracy record.
Castro, 75, has maintained a one-party system and outlawed opposition political groups since soon after his 1959 revolution. He maintains the only communist system in the Americas.