WASHINGTON — Withdrawing American troops from Afghanistan too soon would be a “strategic mistake,” President Trump’s nominee for Joint Chiefs of Staff chairman said Thursday, clearly outlining the Pentagon’s position as the White House wrestles with whether to pull military forces and end the 18-year war.

“I think it is slow, it’s painful, it’s hard — I spent a lot of my life in Afghanistan — but I also think it’s necessary,” Gen. Mark A. Milley, the nominee, said about the American military’s continuing mission at his confirmation hearing before the Senate Armed Services Committee.

General Milley’s tough line on the war comes as the United States and the Taliban navigate their seventh round of peace negotiations.

Earlier peace dialogues have focused on two main planks: the withdrawal of Western troops and the Taliban’s pledge to deny any safe haven to terrorist groups in Afghanistan.