WASHINGTON — President Trump signed legislation on Wednesday imposing sanctions on Russia and limiting his own authority to lift them, but asserted that the measure included “clearly unconstitutional provisions” and left open the possibility that he might choose not to enforce them as lawmakers intended.

The legislation, which also includes sanctions on Iran and North Korea, represented the first time that Congress had forced Mr. Trump to sign a bill over his objections by passing it with bipartisan, veto-proof majorities. Even before he signed it, the Russian government retaliated by seizing two American diplomatic properties and ordering the United States to reduce its embassy staff members in Russia by 755 people.

The measure reflected deep skepticism among lawmakers in both parties about Mr. Trump’s friendly approach to President Vladimir V. Putin of Russia and an effort to prevent Mr. Trump from letting the Kremlin off the hook for its annexation of Crimea, military intervention in Ukraine and its meddling in last year’s American election. Rather than the rapprochement Mr. Trump once envisioned, the United States and Russia now seem locked in a spiral of increasing tension.

Unlike other bill signings, Mr. Trump did not invite news media photographers to record the event, nor did he say anything about it to reporters. He ignored questions about the legislation at an unrelated event and instead relegated his comments to two written statements, one meant for Congress to describe caveats in his approval of the bill and the other issued to reporters to explain his grudging decision to sign.