The ambush on the porous border happened overnight in the southeastern province of Sistan-Baluchestan, home to a large community of minority Sunni Muslims, unlike the rest of Shiite-dominated Iran.
"Fourteen border guards were killed during armed clashes in the region of Saravan, and five others were wounded," the official IRNA news agency said, citing what it called an informed source.
The unnamed source identified the gunmen as "bandits or rebels opposed to the Islamic republic".
"Sixteen rebels linked to groups hostile to the regime were hanged this morning in the prison of Zahedan in response to the death of border guards in Saravan," Mohammad Marzieh, attorney general of Sistan-Baluchestan, was quoted as saying by Fars news agency.
More From This Section
"We warned the rebel groups that any attack targeting civilians or members of the security forces would not go unanswered," he added.
Deputy Interior Minister Ali Abdollahi said that the guards had been killed during the ambush set by Iranians who were "members of hostile groups".
The region has seen bloody clashes over the past few years and officials say that more than 4,000 police officers and soldiers have been killed in three decades of fighting with drug traffickers.
Iran is a major transit route for drugs that originate in Afghanistan and is trafficked across its territory, with much of it bound for Western countries.
People smugglers also use the route to traffick illegal immigrants to Europe, via Iran and Turkey.
The Islamic republic says it is fighting a deadly war against drug traffickers who make up half its prison population.