WASHINGTON (CNN) -- President Obama said Friday he plans to withdraw most U.S. troops from Iraq by the end of August 2010.

President Obama talks about his Iraq War withdrawal plan at Camp Lejeune, North Carolina, on Friday.

Between 35,000 to 50,000 troops will remain in Iraq, he said. They would be withdrawn gradually until all U.S. forces are out of Iraq by December 31, 2011 -- the deadline set under an agreement the Bush administration signed with the Iraqi government last year.

"Let me say this as plainly as I can: By August 31, 2010, our combat mission in Iraq will end," Obama said in a speech at Camp Lejeune, North Carolina.

"By any measure, this has already been a long war," Obama said. It is time to "bring our troops home with the honor they have earned." Watch Obama announce drawdown »

Obama's trip to Camp Lejeune, a Marine Corps base, was his first trip to a military base since being sworn in.

Administration officials, who briefed reporters on the plan, said the remaining troops would take on advisory roles in training and equipping Iraqi forces, supporting civilian operations in Iraq and conducting targeted counterterrorism missions, which would include some combat.

But the ultimate success or failure of the war in Iraq, Obama said, would rest with the Iraqi people themselves. The U.S. "cannot police Iraq's streets indefinitely until they are completely safe," the president said.

It is up to the Iraqis, he said, to ensure a future under a government that is "sovereign, stable and self-reliant."

"We sent our troops to Iraq to do away with Saddam Hussein's regime and you got the job done," he said, referring to the troops.

The U.S. military had also "exceeded every expectation" suppressing the insurgency in the years that followed.

Al Qaeda in Iraq had been dealt "a serious blow," the president added. "The capacity of Iraq's security forces has improved, and Iraq's leaders have made strides toward political accommodation" through steps such as January's provincial elections.

"Iraq is not yet secure and there will be difficult days ahead," he said, but the Iraqi people now have a "hard-earned opportunity ... for a better life."

Obama said he made his decision after reviewing several options presented by key military and civilian advisers. Watch ex-general analyze strategy »

He said that he acted with "careful consideration of events on the ground, with respect for the security agreements between the United States and Iraq, and with a critical recognition that the long-term solution in Iraq must be political, not military."

There are 142,000 U.S. troops in Iraq. During the presidential campaign, Obama pledged to pull out all those troops within 16 months. This plan exceeds that promise by three months.

The administration officials would not say how many of the troops leaving Iraq would be redeployed to Afghanistan.

When asked whether troops might be sent back if Iraq becomes unstable after the pullout, a senior aide said the president has always said he wanted some flexibility on the issue.

The president's troop withdrawal plan is meeting with mixed reviews in Congress. iReport.com: What do you think of the withdrawal plan?

Some Democrats -- including House Speaker Nancy Pelosi -- have expressed concern that the residual force Obama is planning to leave in Iraq is too large.

Sen. John McCain, R-Arizona, however, said in a speech on the Senate floor that he believes Obama's decision is "reasonable" and that he is "cautiously optimistic that the plan that is laid out by the president can lead to success."

McCain, the ranking Republican on the Senate Armed Services Committee, said that a "failing situation in Iraq has been arrested and reversed" due to the "dramatic success of the surge strategy."

He also praised Obama's willingness to leave behind a significant residual force and reassess the situation if conditions change in the future.

"We are finally on a path to success," McCain said. "Let us have no crisis of confidence now."

Next month will mark the sixth anniversary of the start of the Iraqi war.

CNN's Dan Lothian and Suzanne Malveaux contributed to this report.

All About Barack Obama • Iraq War