US President Donald Trump with Pakistani Prime Minister Imran Khan. (Reuters)

US President Donald Trump, speaking at a White House meeting with visiting Pakistani Prime Minister Imran Khan, said on Monday the United States is working with Islamabad to find a way out of the war in Afghanistan.

Trump held out the possibility of restoring US aid to Pakistan, depending upon what is worked out, and offered assistance to Islamabad in trying to ease strained ties with India.

Khan told Trump there was only one solution for Afghanistan and that a peace deal with the Taliban was closer than it had ever been. He said he hoped in the coming days to be able to urge the Taliban to continue the talks.

The United States views Pakistan's cooperation with a deal to end the 17-year-old war as essential but the two countries have a complicated relationship.

Trump wants to wrap up US military involvement in Afghanistan and sees Pakistan's cooperation as crucial to any deal to end the war and ensure the country does not become a base for terrorist groups like ISIS.

Washington wants Islamabad to pressure Afghanistan's Taliban into a permanent ceasefire and participation in talks with the Afghan government.

Trump last year slashed millions of dollars of security assistance to Islamabad, which it accused of serving as a safe haven for terrorists. Pakistan has denied the accusations.

The Pentagon said Pakistan's army chief, General Qamar Javed Bajwa, will meet later on Monday with the top American military officer, chairman of the US Joint Chiefs of Staff General Joseph Dunford.