The strong bipartisan vote of 62-33 sends a clear message to President Barack Obama and the military as they engage in high-stakes talks about the pace of drawing down the 66,000 U.S. troops there, with a White House announcement expected within weeks.
Although the vote was on a nonbinding amendment to a defense policy bill, its significance could not be discounted amid the current discussions.
Thirteen Republicans, including Sen. Richard Lugar of Indiana, the top GOP lawmaker on the Senate Foreign Relations Committee, backed the measure.
Sen. Jeff Merkley, D-Ore., its chief sponsor, argued that al-Qaida is stronger in other parts of the world and that nation-building in Afghanistan has gone off track. His measure endorsed Obama's timetable to withdraw all combat troops by the end of 2014 but pressed for a quicker pace, without specifying how that would be achieved.
"It is time to end this war, end the longest war in United States history," Merkley said during Senate debate.
Defense Secretary Leon Panetta said Thursday the U.S. will need to keep troops in Afghanistan even after the combat mission ends in 2014 because al-Qaida is still present in the country and is trying to strengthen its influence.
He would not say how many American troops he thinks will be needed to conduct that mission, nor did he mention a time period.
"The goal here is an enduring presence therefore that will direct itself toward three important missions. One is obviously counterterrorism to insure that we continue to go after whatever al-Qaida targets remain in Afghanistan," Panetta told reporters at a Pentagon news conference.
He added that the United States also will have to train and assist the Afghan forces while providing support.
The overall defense bill authorizes $631 billion for weapons, ships, aircraft and a 1.7 percent pay raise for military personnel. The White House threatened to veto the legislation in its current form, citing limits on the president's authority in handling detainees at the U.S. military facility at Guantanamo Bay, Cuba, and restrictions on cuts to the Air National Guard and Air Force Reserve.
The Senate hopes to wrap up its version of the bill by week's end. It then would have to be reconciled with the legislation the House passed in May. The House bill calls for Obama to maintain a force of at least 68,000 troops in Afghanistan through the end of 2014.
Late Thursday, the Senate revived last year's debate over how to handle terror suspects and whether restrictions interfere with the president's powers as commander in chief.
Lawmakers approved an amendment that would prevent the transfer of detainees held at Guantanamo Bay, Cuba, to prisons in the United States. The vote was 54-41, with several Democrats vulnerable in the 2014 elections voting with Republicans.
Sen. Kelly Ayotte, R-N.H., argued that the 166 terror suspects, including Khalid Sheikh Mohammed, the self-styled mastermind of the Sept. 11, 2001, attacks, should remain at the U.S. naval facility and not be transferred to any facility on American soil.
Responding to Ayotte, Sen. Dianne Feinstein, D-Calif., the chairwoman of the Senate Intelligence Committee, said the United States not only can but has handled terrorist suspects, with 180 now languishing in super maximum prisons. Feinstein complained that the measure would erase the president's flexibility.
"I don't think the right thing to do is to tie anyone's hands," she said.
Senate Armed Services Committee Chairman Carl Levin, D-Mich., who had pushed for several of the provisions on terror suspects in last year's defense bill, said Ayotte's measure was "unwise in terms of our national security." He also warned that the provision was certain to draw a presidential veto.
In fact, the administration, in threatening to veto the bill, strongly objected to a provision restricting the president's authority to transfer terror suspects from Guantanamo to foreign countries. The provision is in current law.
The White House said the provisions were "misguided when they were enacted and should not be renewed."
Current law denies suspected terrorists, including U.S. citizens seized within the nation's borders, the right to trial and subjects them to the possibility they would be held indefinitely. It reaffirms the post-Sept. 11 authorization for the use of military force that allows indefinite detention of enemy combatants.
An unusual coalition of liberal Democrats and libertarian Republicans backed an amendment by Feinstein that said the government may not detain a U.S. citizen or legal resident indefinitely without charge or trial even with the authorization to use military force or declaration of war.
Feinstein recalled the dark days of World War II when the United States forcibly removed thousands of Japanese-Americans and placed them in permanent internment camps amid unfounded fears that they were spies and a national security threat.
Civil rights groups said the measure did not go far enough, but it was approved on a 67-29 vote with the backing of conservative Sens. Rand Paul, R-Ky., and Mike Lee, R-Utah.
The Senate eliminated one provision from the bill that had attracted White House objections. In a strong bipartisan vote Wednesday, senators voted to allow Pentagon investment in alternative fuels.
AP National Security Writer Robert Burns contributed to this report.