WASHINGTON — The White House said on Friday night that President Trump would sign legislation imposing sweeping sanctions against Russia and curtailing his own power to lift them by himself, bowing to the near-universal bipartisan will of Congress at the risk of escalating tension with Moscow.

“President Donald J. Trump read early drafts of the bill and negotiated regarding critical elements of it,” Sarah Huckabee Sanders, the White House press secretary, said in a written statement released late in the evening. “He has now reviewed the final version and, based on its responsiveness to his negotiations, approves the bill and intends to sign it.”

Mr. Trump had little choice given that the bill passed the Senate on Thursday by a whopping 98-to-2 vote, two days after clearing the House by a 419-to-3 margin. Had Mr. Trump vetoed the legislation, he faced the politically embarrassing prospect of being overridden by a Congress controlled by his own party on a measure to penalize Moscow at the same time his associates are being investigated for their contacts with Russia.

The Kremlin retaliated even before the president announced his decision, seizing two United States diplomatic properties in Russia and ordering the embassy to reduce its staff by September. European leaders have expressed opposition to the measure because they argue that the United States and its allies should remain in concert on actions taken against Russia. Energy companies in the United States also objected to measures that they worried would put them at a competitive disadvantage.