WASHINGTON — Mitt Romney abruptly moderated his foreign policy positions in Monday’s debate on such issues as ending the war in Afghanistan and averting another conflict in Iran, hoping to neutralize one of President Barack Obama’s main strengths with the election two weeks away.

But the move toward the political center comes with potential pitfalls.

By abandoning several of his sharpest criticisms of Obama from the past several months, Romney risks upsetting some conservatives and reinforcing the allegation, levied repeatedly by the president on Monday night, that his positions lack conviction and leadership.

His aim was to appear sober and serious, a plausible commander in chief, by not engaging in saber-rattling for political points. By narrowing the gap between his positions and those of Obama, he also may have succeeded in giving undecided voters, particularly women, the impression that he would lead a war-weary America into another conflict only reluctantly.

The main goal, Romney aides said, was for him to look like a suitable commander. After adopting a more militaristic tone to win the GOP nomination amid challenges from more conservative candidates, he sought at all costs to avoid appearing as a warmonger.

“I want to see peace,” Romney said in his closing statement.

The shifts in the debate were stark for a candidate who only last week described Obama’s foreign policy as “unraveling before our very eyes.”

Unconditionally endorsing Obama’s 2014 deadline for removing U.S. combat troops from Afghanistan, Romney reversed his opposition to what he had termed a “political” timetable that wasn’t necessarily supported by U.S. generals on the ground.

And he declared the president’s troop surge in Afghanistan a success, after previously accusing Obama of removing too many troops too quickly.

Romney’s move toward the center on foreign policy follows a similar shift he has tried to engineer on domestic issues.

In recent weeks he has softened his rhetoric on immigration and used a TV ad to emphasize his support for abortion rights in instances of rape and incest and if the mother’s health is threatened, all risky positions in a GOP primary battle.