The official identified the two men as guards at the French embassy, but a diplomatic source was unable to confirm this.
Their Yemeni driver was also wounded in the attack, the security official said, adding that the assailants fled.
Authorities have launched an investigation into the attack, which took place a few hundred metres (yards) from the embassy, said the official, who could not immediately provide details on possible motives.
Foreign diplomats, mainly Europeans, have increasingly come under attack in Sanaa.
A German diplomat was wounded in the Yemeni capital on April 28 as he evaded an attempt by gunmen to kidnap him in the same district.
Last October, a German embassy security guard was killed as he resisted a kidnapping attempt.
Two Britons and a German were kidnapped in January and February respectively.
Yemen, a deeply-tribal country where most men are armed, is home to Al-Qaeda in the Arabian Peninsula, which is seen by Washington as the most potent franchise of the global network after being linked to a number of attempted attacks on the US homeland.
Al-Qaeda militants hold captive Saudi diplomat Abdullah al-Khalidi, who was kidnapped from the southern city of Aden in March 2012, and Iranian diplomat
Nour-Ahmad Nikbakht, kidnapped in July 2013 from Sanaa.