The assailants attacked Humayoon Rasaw late Sunday on a street in the centre of town, throwing him to the ground to steal his watch, a police spokeswoman said.
The ambassador, who was in Barcelona for celebrations marking war-torn Afghanistan's national day, suffered a leg injury but “is fine,” according to a source at the Afghan embassy in Madrid.
The robbery comes as Barcelona, one of Europe's most visited cities, has seen a sharp rise in crimes, including several involving foreigners which have made global headlines.
The Mediterranean city has seen eight murders since July, an unusually high number in Spain which has one of the lowest crime rates in Europe.
Robberies, especially those targeting foreign visitors, have also risen.
Recorded thefts in Spain's second-largest city, home to around 1.6 million people, have doubled over the past four years.
In the first half of 2019, violent robberies jumped by 31 percent over the same period last year.
In late June a South Korean woman who was part of an official government delegation died after a thief snatched her purse, causing her to fall and seriously injure her head.
Earlier this month a Chinese man died in a fight outside a Barcelona nightclub.