The Senate voted 50-48 in favor of the war powers resolution, which passed the House of Representatives early this month, reflecting growing concern even among some of Trump's Republicans about the unpopular conflict that began on February 28 when the US and Israel launched an attack on Iran.
It was the first time both chambers of Congress had passed a resolution directing a president to remove US armed forces from hostilities since the War Powers Resolution, more commonly known as the War Powers Act, was enacted in 1973, Reuters reported.
While likely to remain largely symbolic, the vote was a setback for Trump, who until recently had enjoyed near-unanimous support from Republican members of Congress.
It also comes as the administration is expected to ask Congress to authorize tens of billions of dollars to pay for the war.
Trump's Republicans hold slim majorities in both the Senate and House, but a few have broken with the president on a handful of issues ahead of mid-term elections in November, which will determine whether the party will retain control of Congress.
Some Republicans recently balked at Trump's $1.8 billion "anti-weaponization" fund to compensate political allies he says have been targeted by federal authorities and stalled a $70 billion bill to fund his immigration crackdown.
Reuters/Ipsos poll results released on Tuesday showed that just one in four Americans believe the war against Iran was worth its costs, and a majority worry that a truce with Tehran is unlikely to last.
The Senate vote was largely along party lines, with four Republicans joining all but one Democrat in favor. Two Republican senators did not vote.
Trump's administration is working to negotiate a peace agreement with Iran. Support for the resolution in Congress is likely to put pressure on the president not to resume hostilities, something he has suggested he might do if negotiations falter.
Under the 1973 War Powers Act, the concurrent resolution - passed by both the House and Senate - does not go to the White House for Trump's signature. In the 1973 law, Congress intended such resolutions as a mechanism for ending military operations.
But legal experts said the issue remains unsettled. No war powers resolution had previously passed both chambers of Congress and a 1983 Supreme Court ruling said such a measure must be submitted for a president's signature or veto to have legal effect.