US troops Afghanistan
On the final day of a monthlong anti-Taliban operation by the Afghan National Army in various parts of eastern Nangarhar province, U.S. soldiers participate in a NATO patrol at an ANA base in the Khogyani district Aug. 30, 2015. Getty Images/AFP/Noorullah Shirzada

The United States has changed its policy in Afghanistan, opting to keep U.S. Army troops in the country, President Barack Obama said Thursday.

Roughly 9,800 troops will remain in Afghanistan until the end of 2015, senior U.S. administration officials told ABC News. According to NBC News, more than half of those soldiers will stay until 2017.

Last year, Obama announced that he would achieve his goal of “ending two wars” during his second term as president. All U.S. troops, except roughly 1,000 military personnel working at the American embassy in the capital, Kabul, were expected to leave Afghanistan by the end of this year.

Keeping additional troops in Afghanistan will cost the U.S. an estimated $14.6 billion, which is nearly $5 billion more than the cost for Obama’s original strategy, U.S. officials told NBC News.

The policy shift in Afghanistan comes on the heels of major gains by Taliban insurgents in the country over the last month.

Afghanistan also saw the rise of the Islamic State group this year. In December, ISIS announced the expansion of its so-called caliphate into the Khorasan region, which includes Afghanistan. Since then, militants have made gains in the country, fighting both the Afghan army and Taliban insurgents.