Shoigu is the most senior Russian military official to visit Tehran since 2002, according to Iranian media, and the agreement comes with both countries facing Western sanctions.
The deal provides for joint exercises and military training, as well as "cooperation in peacekeeping, maintaining regional and international security and stability, and fighting against separatism and extremism," the Iranian defence ministry website said.
Defence Minister Hossein Dehqan told state television that Iran and Russia had a "shared analysis of US global strategy, its interference in regional and international affairs and the need to cooperate in the struggle against the interference of foreign forces in the region."
Iran demanded USD 4 billion in compensation for the cancellation of the USD 800 million order.
More From This Section
"The two countries have also decided to settle the S-300s problem," the Iranian defence ministry said, without elaborating.
As Russia has been hit by Western sanctions over its involvement in the conflict in Ukraine, it has stepped up its economic ties with Iran in the past year.