Judge John Osiemo said none of the prosecution's evidence had connected the men to the bombing, which killed 15 people.
Under Kenyan law, a judge can acquit defendants after the prosecution has finished presenting its case if he finds the case insufficient.
Omar Said Omar, Mohammed Nabhan, Aboud Rogo Mohammed and Mohammed Kubwa were immediately released.
"It's fair, I'm quite happy I'm back with my family, justice has been done," Nabhan said.
Prosecutor Edwin Okello said he was disappointed with the ruling.
"The judge did not appreciate the issues we made connecting the accused to known terrorists," he said.
"It's fair, I'm quite happy I'm back with my family, justice has been done"
Mohammed Nabhan, one of the men released
The attack on the Israeli-owned Paradise hotel, north of the Indian Ocean port of Mombasa on 28 November 2002, killed 15 people, including three Israeli tourists. It was linked to al-Qaida.
The trial, along with another of three suspects charged with conspiracy, marked the first attempts by the authorities in the East African country to prosecute alleged terrorists.