"Two armed men tried to kidnap a foreign citizen as he was leaving a barber in Hadda Street in Sanaa," the ministry's 26sep.net site said of the unprecedented incident.
"But he was able to resist and shot them with a revolver he had in his possession," the website said, citing security sources.
It added that accomplices of the gunmen in a car with no number plates managed to get away.
The ministry gave no indication of the intended victim's nationality or that of those who planned to kidnap him.
Nor did it say whether the foreigner was arrested after the shooting.
But security sources told AFP the man is a Russian expert working in the oil sector, and that his attackers were Yemenis from the Marib region east of Sanaa.
Witnesses gave a different version of events, saying the foreigner had two guards and that they gunned down the armed men.
Signup to our newsletter and follow us on Facebook and Twitter!
Security sources were unable to confirm this.
Thursday's incident was the first time that an attempted kidnapping in Yemen -- where such incidents are common -- has ended in the deaths of the aggressors.
Heavily armed tribesmen are generally behind such kidnappings, hoping to put pressure on the authorities to resolve a grievance, and in most cases their hostages are later freed unharmed.
However, Al-Qaeda in the Arabian Peninsula, which the United States views as the most deadly franchise of the extremist network, has also kidnapped foreigners.
Last May, AQAP seized South African Pierre Korkie and his wife Yolande, and is demanding a $3-million (2.2-million-euro) ransom for his return.
Mrs Korkie was released in January.
Al-Qaeda militants are also suspected of having kidnapped two diplomats in the southern port of Aden -- a Saudi and an Iranian.