Saudi Arabia’s Crown Prince Mohammed bin Salman has been shunned by much of the world after the murder of dissident journalist Jamal Khashoggi in October, which the CIA concluded he had ordered. A-list executives pulled out of his Riyadh investment forum (dubbed ‘Davos in the Desert’), street protests greeted his arrival in Tunisia in November, and there were reports Morocco’s King Mohammed VI snubbed him on a visit to the North African country. That wasn’t the case earlier this week in Pakistan, however, which bestowed its highest civilian award on the young Saudi prince, gave him a gold-plated gun, and declared Monday a public holiday in honor of his two-day visit to Islamabad.

“Saudi Arabia has always been a friend in need, which is why we value it so much,” Pakistani Prime Minister Imran Khan said Sunday, while seated next to MBS, as the crown prince is known. Earlier Saudi’s de-facto leader had announced investments in Pakistani petrochemicals, power generation, and mining projects worth more than $20 billion.

In addition to the staggering financial package, MBS — on Khan’s request — ordered the “immediate release” of more than 2,000 Pakistani prisoners incarcerated in the Kingdom. He “won the hearts of the people of Pakistan,” the prime minister — who broke protocol to personally drive MBS to his official residence — later gushed on Twitter.

MBS’s visit to Islamabad is widely regarded as an attempt to repair his tarnished credentials as an international statesman. It precedes stops in India and China, which—like Pakistan—have not spoken out about Khashoggi’s murder. But Saudi Arabia’s investment in the nuclear-armed South Asian state is more than just a PR exercise.

Why does Pakistan need Saudi funds?

Saudi Arabia has a long history of providing financial support to Pakistan. That includes funneling money through Pakistan’s madrassa education system, cushioning the impact of international sanctions following its nuclear test in the late 1990s, and loaning Islamabad $1.5 billion when the Pakistani rupee crashed in 2014.

But the latest round of investment comes at a critical time for Islamabad, which is in the middle of an economic crisis. The foreign exchange reserves that Pakistan uses to purchase crucial fuel imports have dwindled to less than $8 billion. Since he was sworn in as prime minister last August, the populist Khan has been engaged in a highly public “austerity drive” while appealing to friendly nations for financial support.

In fact, in October his government received Saudi funds to the tune of $6 billion, including $3 billion import payment deferrals. The Kingdom proffered that support package after Khan’s visit to Riyadh, when Pakistan’s central bank reserves had plummeted 40% on the previous year’s figures. Islamabad is currently negotiating a bailout from the IMF—the country’s 13th since the 1980s.

What are the economic incentives for Saudi Arabia?

Historically known for spending lavishly to win hearts and minds, the Saudi Kingdom now faces financial constraints of its own. It urgently needs to diversify its oil-dependent economy. “The largesse that the Saudis were able to afford in the 80s and 90s, we haven’t seen recently, and we definitely haven’t seen it under MBS,” says Andreas Krieg, a Middle East security expert at King’s College, London. The pledged $20 billion in not just “a bailout they do because they like the Pakistanis,” he says. Instead there is oversight to ensure investments are “sustainable and will actually have returns in the future.”

Some $8 billion of the funds pledged to Pakistan have been earmarked for the construction of an oil refinery at Gwadar Port, the jewel in the crown of the China–Pakistan economic corridor and an area in which Saudi Arabia’s Gulf neighbor UAE has also invested. With Beijing set to pump some $62 billion into the economic corridor under its transnational Belt and Road Initiative, Saudi stands to massively increase its own oil export market in Pakistan.

How might Saudi money affect regional dynamics?

Khan’s government has welcomed Saudi’s $20 billion investment pledge but “it’s one that’s potentially fraught with risk,” says Farzana Shaikh, associate fellow at the London-based think tank, Chatham House.

Gwador Port is situated in Pakistan’s restive Balochistan province, which borders Iran’s similarly volatile Sistan and Baluchestan Province. On Feb. 13 a Sunni militant group claimed responsibility for a terrorist attack that killed 27 Revolutionary Guards on the Iranian side of the border. Iran blames Pakistan for sheltering militants and accuses Saudi of promoting Sunni violence against its majority Shi’ite population. Pakistan has been trying to “navigate this very delicate terrain between Saudi and Iranian interests in the region, and the attempt of each one to establish its own regional hegemony in this part of the world,” Shaikh says.

Saudi’s investment also risks exacerbating Pakistan’s conflict with India. MBS arrived in New Delhi Tuesday as tensions flared between the nuclear-armed neighbors in the wake of the deadly Feb. 14 terrorist attack in Indian-administered Kashmir. Pakistan-based militant group Jaish-e-Mohammad—which Shaikh says has been a recipient of funds originating from Saudi Arabia—claimed responsibility for the attack, which killed at least 40 Indian paramilitary police. Before leaving Islamabad Monday, Saudi Arabia’s Foreign Minister said the Arab state would work to “de-escalate tensions” between India and Pakistan, but New Delhi is likely to regard Saudi’s bumper investment in its regional rival with wariness.

Is there a military quid-pro-quo?

The optics seem to suggest that. Fighter jets flanked MBS’s inbound plane, a troop of soldiers fired off a 21-gun salute, and a spokesman for Pakistan’s armed forces told Arab News the country’s military is committed to “standing by our Saudi brethren.” Pakistan’s military is among the 20 most powerful in the world, according to U.S. website Global Firepower and the country is one of only eight to have declared possessing nuclear weapons. Global Firepower ranks nuclear-armed India’s military the world’s fourth most powerful.

“Pakistan is providing capacity to militaries across the Gulf, but particularly Saudi Arabia. They couldn’t function without the Pakistanis,” says Krieg, the Middle East security expert, adding that estimates of how many Pakistani soldiers are serving in the Kingdom go as high as 65,000. “If ever relations went sour, Saudi Arabia wouldn’t have another source of manpower to fuel the massive military machine,” Krieg says.

Separately, Saudi Arabia has long been rumored to have nuclear weapons “on order” from Pakistan. Although Riyadh currently purchases billions of dollars worth of weapons from the U.S., the U.K., and other nations, the U.S. Deputy Energy Secretary recently said Washington would not help the Kingdom develop nuclear technology without guarantees it would only be used for civilian purposes, CNBC reports. In addition to its economic pivot to Asia, Riyadh is attempting to diversify its supply of military assets, Krieg says. “The Pakistanis are a very important part of this because they can procure technology that nobody else might be willing to procure at this point.”

Write to Joseph Hincks at joseph.hincks@time.com.