The US will slash troop levels in Afghanistan and Iraq to their lowest levels in nearly 20 years of war after President Donald Trump pledged to end conflicts abroad, the Pentagon announced.

Rejecting concerns that precipitous drawdowns could give up all the US has fought for, Acting Defense Secretary Chris Miller said around 2,000 troops would be pulled from Afghanistan by 15 January.

Another 500 will come back from Iraq by the same date, leaving 2,500 in each country.

The moves reflect Mr Trump's policy "to bring the wars in Afghanistan and Iraq to a successful and responsible conclusion and to bring our brave service members home", Mr Miller said.

Mr Miller said the US had met its goals, set in 2001 after the Al Qaeda attacks on the United States, to defeat Islamist extremists and to help "local partners and allies to take the lead in the fight".

"With the blessings of providence in the coming year, we will finish this generational war and bring our men and women home," he said.

However, allies and senior US politicians have said that US troop cuts were dangerous.

US Senate Majority Leader Mitch McConnell warned the Afghan cuts could lead to a debacle like the "humiliating American departure from Vietnam" in 1975, and be a propaganda victory for Islamic extremists.

NATO chief Jens Stoltenberg warned that Afghanistan could return to being "a platform for international terrorists to plan and organise attacks on our homelands".

Democratic Senator Jack Reed, who sits on the Senate Armed Services Committee, accused Mr Trump of a "cynical, chaotic approach" designed to burnish his own legacy while leaving a mess to successor Joe Biden.

But another senior Democrat, House Armed Services Committee Chairman Adam Smith, said that after speaking with Mr Miller, he saw the move as "the right policy decision".

Ending 'endless wars'

The moves took the US closer to disengaging from conflicts that have blazed and smouldered through three presidencies with no end in sight since 2001.

The announcement came just weeks before Mr Trump cedes the White House in the wake of his reelection loss to Democrat Joe Biden.

Amid criticism that Mr Trump was acting abruptly since his defeat, White House National Security Advisor Robert O'Brien said the troop cuts have been in the works for some time.

"Four years ago President Trump ran on a promise to put a stop to America's endless wars," he said.

US National Security Advisor Robert O'Brien speaks to reporters at the White House

"Today it was just announced at the Pentagon that President Trump is keeping that promise to the American people."

"By May it is President Trump's hope that they will come home safely and in their entirety."

It comes ten days after Mr Trump fired defense secretary Mark Esper, who had insisted on keeping 4,500 troops in Afghanistan to support Afghan security forces.

Mr Esper had reduced US forces from about 13,000 following a deal with the Taliban in February, in which both sides agreed the Taliban would enter into peace talks with the Kabul government, in return for US troops withdrawing by May 2021.

But until Mr Esper's removal, the Pentagon had argued that the Taliban had not met pledges to reduce violent attacks, which have surged across the country in recent months.

Donald Trump fired Mark Esper last week (file pic)

President Ashraf Ghani's spokesman Sediq Sediqqi confirmed in a tweet that Mr Ghani and Mr Miller had spoken on the phone about "continued meaningful US military support to the Afghan Security and Defence Forces".

In Iraq, Mr Trump has also pulled back US forces amid dozens of rocket attacks by Iran-allied groups on the US embassy and bases housing American troops.

On Tuesday, a volley of rockets slammed into Baghdad's Green Zone, where the US embassy sits, breaking a month-long truce on attacks against the US embassy.

Speaking on grounds of anonymity, a senior US defence official dismissed concerns over the risk of resurgences by Al Qaeda and the Islamic State.

"The professionals in the military service have agreed that this is the right move," the official said.

"Al Qaeda has been in Afghanistan for decades and the reality is, we'd be fools to say they are going to leave tomorrow."