The six, who were initially sentenced in March to two years in prison, were part of an 11-member group prosecutors had accused of receiving military training in Afghanistan and planning attacks against Americans and other Westerners in Saudi Arabia, Syria, and Iraq.
Judge Saeed al-Qataa said in Sana on Saturday all 11 men were innocent of the charge of forming an "armed gang".
Abd al-Raouf Naseeb, who was arrested last year and described by Yemeni authorities as a senior agent of al-Qaida, was among the acquitted men.
The judge said Naseeb was innocent of all charges against him.
Naseeb had been sought by Yemeni police and US officials and was believed to have survived the November CIA 2002 drone attack that killed al-Qaida's alleged chief agent in Yemen.
He was also believed to have planned the 2003 prison breakout of 10 fighters linked to the October 2000 attack of the destroyer USS Cole, which killed 17 American sailors.
Naseeb was not being tried for these charges.
The verdict prompted shouts of "God is Great" by the defendants, who were dressed in blue prison uniforms and crammed inside a courtroom jail. The defendants were overjoyed at the ruling.
The judge ruled eight of the men guilty of forgery or possession of personal weapons, upholding some of the defendants' convictions on those counts and handing down some new ones.
The trial in the Yemeni capital
was held under tight security
But all eight were ordered released immediately as they have served enough time in detention.
At the end of the hearing, the defendants, some of whom had been extradited from Iran, Saudi Arabia and Syria, were taken by police back to prison, pending the finalisation of the acquittal procedures, lawyers said.
The trial, which was held under tight security, was the latest in a series of Yemeni cases involving alleged terrorism.
Following the 11 September 2001 attacks on the US, Yemen's government joined the American-led war on terror.