The letter, which arrived by regular post, exploded as the guard opened it in the embassy garden, said the central government’s representative in Madrid, Mercedes Gonzalez.
“Fortunately it was not serious, the person has a small injury to his right hand. The letter was addressed to the ambassador,” she said during an interview with TV station Telemadrid.
A police source said the man had been “lightly” injured and “went himself to a hospital” for treatment.
Spain’s National Police force were informed at around 1:00 pm (1200 GMT) of an explosion at the Ukranian embassy in Madrid, the source added.
A security cordon was put in place by the police around the embassy, located in a leafy residential area in northern Madrid.
A man who lives in front of the embassy, who asked not to be identified, told AFP that he had stepped out to walk his dogs and now police were preventing him from returning home.
“I heard it, I thought it was gunshot. It was not too loud,” he said.
Ukrainian Foreign Minister Dmytro Kuleba ordered the strengthening of security at all Ukrainian embassies, Ukraine’s foreign ministry spokesperson Oleg Nikolenko said on social media after the letter bomb went off.
Spain’s Foreign Minister Jose Manuel Albares has spoken with Ukraine’s ambassador to Spain by telephone “to ask about the well-being of the Ukrainian worker who was injured,” the Spanish foreign ministry said in a statement.
Albares also contacted Kuleba by telephone to express his “support and solidarity”, it added.