The Senate on Thursday approved sweeping sanctions against Russia, forcing President Trump to decide whether to accept a tougher line against Moscow or issue a politically explosive veto amid investigations into ties between his presidential campaign and Russian officials.

The Senate vote, 98 to 2, followed the passage of a House bill this week to punish Russia, Iran and North Korea for various violations by each of the three American adversaries. In effect, the measure would sharply limit Mr. Trump’s ability to suspend or lift sanctions on Russia — handcuffing a sitting president just six months into his term with the nearly unanimous support of a Republican-led Congress.

The Trump administration has opposed the sanctions against Russia, arguing that it needs flexibility to pursue a more collaborative diplomacy with a country that, by American intelligence consensus, interfered in last year’s presidential election. But now the president faces a decision he had hoped to avoid, even though the administration supports sanctions against Iran and North Korea.

The Run-Up

The podcast that makes sense of the most delirious stretch of the 2016 campaign.

White House aides have acknowledged privately that a veto would be politically awkward, at best, for Mr. Trump to justify during the continuing investigations into whether his campaign colluded with Russia.

Last week, after House and Senate leaders announced an agreement on sanctions, Sarah Huckabee Sanders, the incoming White House press secretary, suggested that Mr. Trump would sign the final package. Since then, though, the administration has hedged, saying that Mr. Trump will have to review whatever plan reaches his desk.

“The administration supports sanctions against Russia, Iran and North Korea. We continue to support strong sanctions against those three countries,” Ms. Sanders said on Thursday. “And we’re going to wait and see what that final legislation looks like, and make a decision at that point.”

The sanctions target suppliers of weapons to the Assad regime in Syria and those undermining cybersecurity, among others. The Senate last month passed a similar bill, 98 to 2, that punished only Russia and Iran.

But the effort had languished for weeks amid technical holdups in the House, compelling Democrats to accuse Republicans of stalling on the president’s behalf. As the legislation sat, the administration lobbied against it, finding common cause with oil and gas companies, defense contractors and other financial players who argued that some of the sanctions provisions could harm their profits.

The House version included a handful of changes from the initial Senate bill, some made in response to concerns raised by American energy companies. Those tweaks, combined with the addition of sanctions against North Korea that were drafted by the House, helped end the impasse.

On Tuesday, the House approved the measure, 419 to 3.

Now, as ever, attention turns to the president.

Senator Bob Corker, Republican of Tennessee and chairman of the Senate Foreign Relations Committee, said he “cannot imagine” Mr. Trump rejecting legislation with such veto-proof majorities in Congress.

“If I were giving advice to the president, which I’m not on this issue,” he began before offering some, “it’s just not a good way to start a presidency to veto something and then be soundly overridden.”

For years, a hawkish approach to Russia has been central to Republican foreign policy doctrine. But conservative lawmakers have found themselves at odds with their own president amid Mr. Trump’s stated desire to find common ground with Russia, against the background of Russia-tinged scandals that have consumed his administration.

Senator John McCain, Republican of Arizona, who has long advocated an aggressive stance toward Russia, cheered colleagues for summoning bipartisanship “to respond to Russia’s attack on American democracy.”

“We will not tolerate attacks on our democracy. That’s what this bill is all about,” Mr. McCain said. “We must take our own side in this fight, not as Republicans, not as Democrats, but as Americans.”

Democrats took more explicit aim at Mr. Trump, suggesting that the legislation reflected a dim view of his credibility on Russia.

“This bill will prevent President Trump from relaxing sanctions on Russia without congressional review,” said Senator Sherrod Brown, Democrat of Ohio, who urged Mr. Trump to sign the legislation as quickly as possible. “We’re all concerned about that.”

Senator Jeanne Shaheen, Democrat of New Hampshire, called on Republican leaders in Congress to publicly commit to overriding any veto, in the hopes of deterring Mr. Trump before he tries. And Senator Chuck Schumer of New York, the minority leader, said that “it won’t matter what President Trump decides” given Congress’s overwhelming support for the sanctions.

The Kremlin’s perspective on the matter is clear.

Several days ago, as details of the final sanctions agreement came into focus, Dmitri S. Peskov, a spokesman for President Vladimir V. Putin, was asked by the government-run news agency RIA to characterize Moscow’s view.

Highly negative,” he said.