"The two countries are not allowed to provide a third country with bases to attack either of them," Iranian Defence Minister Ali Shamkhani said after signing the agreement with Azerbaijan's visiting Defence Minister Safar Abiyev.
No further details on the accord were given.
During a meeting with Abiyev on Sunday, Iranian President Mohammad Khatami described the presence of foreign troops in the region as "a threat to the security and peace of regional countries".