The pact, which was first proposed in January 2016, forms part of Beijing's trillion-dollar Belt and Road Initiative.
Iran and China have signed a "25-year strategic cooperation pact" as the US rivals move closer together.
The agreement, which has been kept almost entirely under wraps, was signed on Saturday by the foreign ministers of the two countries, Mohammad Javad Zarif and Wang Yi.
The pact, which was first proposed in January 2016, forms part of Beijing's trillion-dollar Belt and Road Initiative, a plan to fund infrastructure projects and increase its sway overseas that has been a flagship project for Chinese President Xi Jinping.
"Our relations with Iran will not be affected by the current situation, but will be permanent and strategic," Chinese foreign minister was earlier quoted by Iranian news agencies as saying.
"Iran decides independently on its relations with other countries and is not like some countries that change their position with one phone call," Wang said.
Example of 'successful diplomacy'
Wang met President Hassan Rouhani ahead of the signing of the agreement, which is expected to include Chinese investments in key sectors such as energy and infrastructure.
The accord is an example of "successful diplomacy," Rouhani’s adviser Hesameddin Ashena was cited by Iranian media as saying.
"A country's strength is in its ability to join coalitions, not to remain isolated."
Saeed Khatibzadeh, an Iranian Foreign Ministry spokesman, said the document was a "roadmap" for trade, economic and transportation cooperation, with a "special focus on the private sectors of the two sides."
China, one of Iran's largest trading partners and a long-standing ally, agreed in 2016 to boost bilateral trade by more than 10 times to $600 billion over a decade.
Its Commerce Ministry said on Thursday that Beijing will try to safeguard the 2015 Iran nuclear deal and defend the legitimate interests of Sino-Iranian relations.
Row with US
The United States and the other Western powers party to the deal are at odds with Tehran over which side should first return to the accord, which was abandoned by former US President Donald Trump in 2018.
Wang's visit to Tehran comes just days after he hosted Russian Foreign Minister Sergey Lavrov for talks in the Chinese city of Guilin.
The three governments all face difficult relations with Washington after President Joe Biden's administration vowed to remain firm in its dealings with them, despite a renewed emphasis on diplomacy.