Media playback is unsupported on your device Media caption President Obama met with his Afghan counterpart Ashraf Ghani at the White House

The US will keep nearly 10,000 troops in Afghanistan throughout 2015, delaying plans for a gradual withdrawal, the White House has said.

The US and Afghanistan announced the change of plan at a press conference in Washington between President Barack Obama and President Ashraf Ghani.

Despite ongoing security issues there, Mr Obama has promised to end America's longest war by the end of his term.

The US will now leave a small force at the US embassy by the end of 2016.

Originally, officials planned to cut the US troop presence to 5,500 by the end of 2015.

The leaders discussed troop numbers over a working lunch and in meetings, before the press conference on Tuesday.

With the prospect of a tough spring fighting season on the horizon, Islamic State militants trying to recruit on Afghan soil and other security concerns, the US will keep 9,800 troops in Afghanistan.

"Afghanistan remains a very dangerous place," Mr Obama said on Tuesday, adding the size of the US troop presence for 2016 will be decided later this year.

Mr Obama also said Mr Ghani's visit was an "opportunity to begin a new chapter between our two nations".

Analysis: Jon Sopel, BBC North America Editor

What a difference a change of president makes. The toxic relationship between Presidents Obama and Karzai is now replaced by something much warmer with Ashraf Ghani.

The substance of course is the most important thing, and at their news conference Mr Obama agreed to delay the drawdown of US troops.

But Mr Ghani clearly understands the importance of feely-touchy politics. He talked about meeting the daughter of a US reservist - and thanked her, and all those other children whose parents serve in Afghanistan.

He also talked about meeting the widow of a US servicemen. He said the most important thing he could do for those who have made the ultimate sacrifice is to create a stable, viable Afghanistan.

I suspect Mr Ghani will have won many US admirers with those words.

The Afghan president said the slower withdrawal would allow Afghan forces to be better trained and equipped.

"Tragedy brought us together - interests now unite us," Mr Ghani said, adding the people of Afghanistan were well-placed "to speak truth to terror"

"They do not speak for Islam, we do."

The lunch and meetings came just as gunmen killed at least 13 people in eastern Afghanistan overnight and, separately, a suspected US drone strike near the Afghan-Pakistani border killed nine militants.

Image copyright EPA Image caption The press conferences comes after two days of meetings between US and Afghan leaders

However, Mr Ghani's presidency is a welcome change in the eyes of the White House, whose relationship with his predecessor grew increasingly strained in recent years.

When he assumed office, Mr Ghani, who lived in the US for more than a decade, almost immediately signed a security deal with American officials to keep US troops in the country beyond 2014.

The refusal of the previous Afghan administration, led by Hamid Karzai, to sign the agreement generated consternation at the White House.

By contrast, Mr Ghani has made clear his appreciation for US support, which has included more than $60bn (£40.37bn) being invested in his country's military so far.

Ahead of the meetings, activist groups were calling on the leaders to make human rights a top priority.

"Both the US and Afghan governments have a legacy of human rights violations to address, from abusive militias in Afghanistan to the mistreatment of detainees at Bagram and Guantanamo," Human Rights Watch said in a statement.

Image copyright Getty Images Image caption Abdullah Abdullah (L) and Ashraf Ghani (C) agreed to share power six months ago

After a controversial election with disputed results, President Ghani agreed to share power with his main political rival, Abdullah Abdullah, who has taken the title of Chief Executive Officer of the country.

Six months into their term, the two leaders have made the trip to the US together in an effort to project unity, despite being unable to build a full cabinet.

In a ceremony at the Pentagon on Monday, Mr Ghani paid tribute to US soldiers who had fought in Afghanistan and thanked the US for its support.

"Each one of you has left a legacy," he said, noting that more than 2,200 Americans lost their lives and 20,000 were wounded in the conflict.