Pakistan has emerged as an apparent winner from the international outcry that followed a Saudi hit team’s murder of journalist Jamal Khashoggi in Istanbul at the beginning of October. By rushing to stand by Saudi Crown Prince Mohammed bin Salman, widely accused of ordering the execution, Pakistani Prime Minister Imran Khan got a $6 billion aid package, which he desperately needs to salvage the Pakistani economy. There undoubtedly is more to the deal, including benefits for Saudi-backed terrorist groups in Pakistan.

Khan was elected in August as a populist who promised to shake up Pakistani politics and fight corruption. He was aided by the all-powerful army intelligence service, the ISI, which was determined to keep former Prime Minister Nawaz Sharif’s party from regaining power. Khan has long been a harsh critic of the United States and friendly to the Taliban.

Better known for leading his country as a cricketer than as a politician, Khan is a man in a hurry. He inherited an economy in crisis, and shortly after the election Khan traveled to Saudi Arabia looking for a bailout.

The Kingdom has been a major aid donor to Pakistan for decades, but the Saudi war in Yemen has strained relations. Nawaz Sharif turned down Mohammed bin Salman’s repeated requests for Pakistani troops to help pursue the war against the Houthis in Yemen. Sharif took the Saudi request to the Pakistani parliament, which unanimously voted against sending troops—a stunning rebuke to Riyadh and the crown prince. Without Pakistani armor the war quickly became a stalemate and an expensive quagmire for Saudi Arabia. It costs at least $50 billion a year and has created one of the world’s worst humanitarian crises.

“ Since the deal was signed, the Pakistani government has removed from a list of proscribed groups two organizations headed by Hafez Saeed – the mastermind of the Mumbai terrorist attack. ”

The Pakistani “no” on Yemen sent another message. For decades, Saudi Arabia had implied that if it ever needed nuclear weapons it would have access to the Pakistani nuclear arsenal, the fastest growing nuclear weapons inventory in the world. But if Pakistan would not send troops to fight the Houthis, it would surely not send the bomb. Mohammed bin Salman, widely known as MBS, had eroded the Kingdom’s deterrent with his reckless behavior in Yemen.

Imran Khan did not get a handout from his first trip in September, but he went back last week, and the Saudi crown prince is now a much-diminished figure in the wake of the Istanbul affair.

Once touted as a reformer who would transform the Kingdom, he is now condemned for the murder of Khashoggi, the humanitarian catastrophe in Yemen, a series of diplomatic gaffes, and repression at home. A much advertised investment conference in Riyadh was boycotted by most invitees from the West. The Saudi cover story changed daily.

Khan got a deal this time. In fact, he got a bigger deal from his second trip than he had asked for on his first. The Saudis provided Khan with a $3 billion balance of payments deposit at a time when Pakistan’s reserves are at a four-year low. In addition, the Saudis agreed to defer payments for oil deliveries to Pakistan for three years, which is worth at least another $3 billion. The Pakistanis are asking the United Arab Emirates, Saudi Arabia’s junior partner in Yemen, for additional aid.

Pakistani Foreign Minister Shah Qureshi has said that there are no strings attached. Asked how the deal happened, the urbane Qureshi said “by the grace of the Holy Prophet.” He was adamant that Pakistan is not changing its approach on Yemen, and since Khan’s party is a strong critic of the war, that’s probably correct. Qureshi also said that the Saudi deal has nothing to do with the ongoing criminal charges against Nawaz Sharif.

Since the deal was signed, the Pakistani government has removed from a list of proscribed groups two organizations headed by Hafiz Saeed—the mastermind of the Mumbai terrorist attack, which took place 10 years ago next month. Saeed was one of the few voices who lobbied to send Pakistani troops to fight in Yemen and he has long raised funds for his terrorist activities in the Kingdom. He also has close ties to the ISI, which trained and assisted the Mumbai killers.

The ISI also has a long record of killing journalists who write about its connections to terrorists like Saeed. He has a $10 million bounty on his head from the United States.

By his own admission, Khan was desperate to get a deal, and he played his cards wisely. He can also seek help from the Chinese and Iranians in the weeks ahead. China has made a multibillion-dollar commitment to build an economic corridor across Pakistan linking western China to the Persian Gulf with a new port at Gwadar on the Gulf of Oman. Khan has said he wants to mediate between Saudi Arabia and Iran to ease tensions in the region and reduce sectarian violence between Sunnis and Shias. Pakistan has a large Shia minority and needs to calm down the Saudi-Iranian proxy war.

The United States also needs Pakistan to help it get out of Afghanistan. Donald Trump is a reluctant warrior in Afghanistan. He agreed to stay last year against his own intuition. The Pakistanis have provided sanctuary and safe havens for the Afghan Taliban for 17 years. The ISI trains them and helps plan their military operations. The army leadership has stonewalled American generals and diplomats from three administrations seeking to end the connection to the Taliban. It’s only gotten stronger.

Pakistan is still in deep economic trouble and will probably need IMF aid. Khan played the Khashoggi backlash to his advantage in Riyadh, but it is way too soon to suggest that he has a coherent plan to make Pakistan prosperous and corruption free. For now, it is amusing to see Mister Bone Saw—MBS’ new nickname—get shaken down by a batsman.