“He is ok now. He is in hospital,” said the spokesman, who declined to disclose the name of the consul.
It was unclear if the attack was an attempt to kidnap the diplomat.
The spokesman said he had been driving ahead of the consul, but when he arrived at the embassy, the consul was no longer following.
The diplomats had been driving without guards, he added.
Witnesses said six masked men attacked the diplomat in a small street, about 250 metres (820 feet) away from the Japanese mission.
They pulled him out of his car and one of the assailants hit him on the head with a pistol butt, before pushing him to the ground and driving off in his vehicle.
Local residents said they administered first aid in a nearby shop, until an embassy vehicle arrived and took him away.
An AFP correspondent found traces of blood in the street.
Foreigners are frequently attacked or kidnapped in Yemen, home to Al-Qaeda in the Arabian Peninsula which is viewed by the United States as the network’s deadliest franchise.
But armed tribesmen also kidnap foreigners to use as bargaining chips to gain government concessions.
A Dutch couple was set free last week after spending six months in captivity.
In late November, unidentified gunmen killed a Belarusian defence contractor and wounded another in an attack outside their hotel in Sanaa.
A German embassy guard was killed in October last month as he resisted an attempt to kidnap him.
Hit-and-run assassinations are frequent in Yemen and are mostly blamed on Al-Qaeda militants, or stem from tribal disputes.
The United Nations closed its offices in Sanaa on Thursday over fears of possible car bombs attacks, and the American and Turkish schools were shut, but Western embassies remained opened.
The alert came after a December 5 brazen daylight attack on the defence ministry complex in Sanaa that killed 56 people, among them expatriate medical staff.
In August, a security alert originating in Yemen prompted an unprecedented closure of American embassies across and beyond the Middle East.
Yemen has been battling through a tough political transition since veteran president Ali Abdullah Saleh was ousted from power in February 2012, following a year of deadly protests against his 33-year rule.
The transition aims to culminate in a new constitution and pave the way for parliamentary and presidential elections in February 2014, but it faces many hurdles.