WASHINGTON — President Obama declared Wednesday that the United States had largely achieved its goals in Afghanistan, setting in motion a timetable for the rapid withdrawal of American troops in an acknowledgement of the shifting threat in the region and fast-changing political and economic landscape in a war-weary America.