Huzam al-Maas and Khalid al-Halila, who had faced a maximum jail term of 10 years for trying to throw a hand grenade at the envoy as he was entering a shop, can appeal their sentence, their lawyers said.
Maas had pleaded guilty to attempting to kill the ambassador, but told the state security court he was psychologically ill.
Halila, a taxi driver, had pleaded not guilty, saying he only drove Maas to a weapons market.
Yemen, the ancestral home of al-Qaida leader Osama bin Laden, has joined the US-led war on terrorism since the September 11 attacks.
It has cracked down on al-Qaida-linked militants after attacks at home including the 2000 USS Cole bombing and the 2002 attack on the French supertanker Limburg.