With pressure mounting on Iran from US sanctions, Iran is placing heavy emphasis on its neighbors for trade and political support.

Pakistani Prime Minister Imran Khan’s recent visit to Iran has raised the question of whether Pakistan can be the friend Tehran needs to survive the Trump administration’s growing hostility.

Khan’s visit, his first since becoming prime minister, coincided with the announcement from the Trump administration that the US will end all waivers for foreign countries to import Iranian oil.

Iranian and Pakistani leaders talked about the importance of developing connectivity between their countries to boost their respective economies. President Hassan Rouhani said, “links between Chahbhar port [in Iran] and Gwadar [in Pakistan can help] to strengthen our commercial ties.” The two leaders also discussed the implementation of bilateral and multilateral agreements, such as China’s Belt and Road Initiative and the China-Pakistan Economic Corridor, in order to increase regional cooperation.

Previous Pakistani prime ministers have also visited Iran and espoused similar views about better ties between the two populous Muslim neighbors. All of them have met with the Supreme Leader Ayatollah Ali Khamenei and talked about the need to improve security along their borders as well as expanding commerce.

However, Khan’s visit seems to have been more calculated. Khan, a Sunni Muslim, went to the city of Mashhad, where there is an important shrine to the eighth Shia Imam. This was a smart move by Khan, who seems to have achieved two goals with his pilgrimage.

First, in addition to paying his respects to his Iranian hosts, Khan was able to show solidarity with Pakistan’s own Shia minority. The predominantly Shia Hazaras in Pakistan have been targeted repeatedly by Sunni extremists including the Islamic State of Iraq and al-Sham (ISIS). A recent attack in Quetta led to days of Hazara protests against the Pakistani government.

Second, without contradicting any of his previous displays of gratitude toward the Saudis for their financial assistance, Khan may have intended to show by visiting Mashhad that Pakistan is not Saudi Arabia’s proxy.

Khan also took the head of Pakistan’s Inter-Service Intelligence (ISI), General Asim Munir, with him on his trip to Iran, as a measure of “trust building” and to increase cooperation on security and the fight against terrorism.

Khan said, “So, the (Pakistani) security chief will be sitting with his counterpart here, and today they will be discussing ways of cooperation so that we have trust in each other that both countries will not allow any terrorist activity from their soil, and we hope that this will build confidence between us.”

Khan’s admission in Iran that Pakistani soil has been used as a base of operations for terrorist attacks against Iran brought heavy criticism from Pakistan’s political opposition.

Khurram Dastagir from the Pakistan Muslim League (PML-N) demanded an explanation as to “how the PM’s admission serves the interest of the country.” PML leader Maryam Nawaz, the daughter of former Prime Minister Nawaz Sharif, accused Khan of “vilifying and defaming” Pakistan. “Imagine what the Iranian leadership would be thinking!” she said.

Members of the National Assembly from the Pakistan Peoples Party (PPP) also expressed dismay over Khan’s statement. Former Foreign Minister Hina Rabbani Khar said “It is worrying to see the country being ridiculed continuously.”

In fact, Iran and Pakistan have been talking about terrorist groups operating along their mutual border for the last few decades. Only days before Khan’s trip, gunmen kidnapped and killed fourteen Pakistani security forces in Pakistan’s southwestern Balochistan province. A Baloch nationalistumbrella group, “Raja Aajoi Saangar,” which Islamabad believes is based on Iran’s side of the border, took responsibility.

Pakistani Foreign Minister Shah Mahmood Qureshi expressed anger over the attack and called on Iran to take action. He also spoke with Iranian Foreign Minister Mohammad Javad Zarif. According to Qureshi, Pakistan has shared evidence related to the attack with Iran, and Tehran has promised to investigate the incident. Pakistan is planning to seal its 950-kilometer border with Iran, Qureshi went on to say.

Pressure on Khan mounted, which forced his office to clarify his statement, saying that “the PM was referring to non-state actors using Pakistani soil under foreign influence to carry out activities in Pakistan or coordinating from Pakistan.”

Relations between Iran and Pakistan, despite typically being described as “brotherly,” have been through many ups and downs. Previous Pakistani administrations have not been especially good friends to Iran. In particular, the two countries have been at odds since the Taliban took power in Afghanistan in the 1990s. There have been bitter instances, such as in 1990 when Sadeq Ganji, director general of an Iranian cultural center in Lahore, was killed by Sunni militants. There was also an attack from the Pakistan-backed Taliban on the Iranian consulate in the Afghan city of Mazar-e-Sharif in 1998. Eight diplomats and a journalist were killed and Iran and Afghanistan nearly went to war.

At the same time, Iran received significant nuclear technology from the former head of Pakistan’s nuclear establishment, Abdul Qadeer Khan.

One issue of perennial interest and disappointment has been the so-called peace pipeline, first discussed between the Iranian and Pakistani governments in the mid-1990s. Designed to provide energy-hungry Pakistan and eventually India with Iranian natural gas, the pipeline originates in the South Pars gas field in Iran’s southern city of Asalouyeh, passes through several Iranian cities in Bandar Abbas and Sistan-Baluchistan, and is supposed to reach Khuzdar in Pakistan and from there continue on to Multan and Karachi.

Iran announced in 2011 that it had completed its part of the project, and offered Pakistan $500 million to construct the Pakistani portion, about a third of the estimated needed funds. Under enormous pressure from both the US and Saudi Arabia, however, Pakistan halted the project. India also withdrew and has been discussing an undersea gas pipeline directly from Iran, though the resumption of US sanctions against Iran has undoubtedly prejudiced those talks.

Another project, the Turkmenistan–Afghanistan–Pakistan–India pipeline, is intended to bring gas from Turkmenistan to India through Afghan and Pakistani tribal regions. That project is facing challenges both in terms of funding and security.

The peace pipeline could have been the answer to Pakistan’s long-term need for energy. However, Pakistan is in dire need of financial help overall and Iran lacks the ability to compete with Saudi Arabia and the United Arab Emirates in this regard, especially now that US sanctions have greatly weakened its economy. Iran is still offering to fulfill Pakistan’s energy needs. Rouhani said in a joint press conference with Khan that Iran is ready to resume work on the gas pipeline where it left off. But Pakistan cannot afford to alienate the Saudis and Emiratis by appearing too close to Tehran.

The Islamic Republic has not had many loyal friends in its forty years of existence. Iran’s major economic partners have not supported Tehran in its times of need. However, this time Pakistan, China, and Iran are all at odds with Washington. It remains to be seen if this alliance, even if it is for a limited time, can help Iran get through one of its most challenging periods since the 1979 revolution.

Fatemeh Aman is a nonresident senior fellow in the Atlantic Council’s South Asia Center. Follow her on Twitter @FatemehAman.