Spanish Foreign Minister Miguel Angel Moratinos said three intruders had "left the building" and that all consulate employees were safe.
"The situation has ended," he was quoted as saying. No further details were available, and the motives of the hostage-takers were not immediately clear.
``It appears the three hostage-takers were interested
``However, this is just speculation. We need time to identify their true motive.''
Earlier, Spanish media reports spoke of a single intruder, a "common criminal" who had stabbed the doorman before entering the building and taking at least two people hostage.
The police had immediately cordoned off the area and positioned sharpshooters around the building.