WASHINGTON — First there was the middle-class tax cut that even his allies and many of his aides had not heard about. Then troops were dispatched to the border to counter an “invasion of our country” by impoverished migrants about 900 miles away.

And then, on Tuesday, President Trump declared that he would sign an executive order essentially rewriting the Constitution as it has been traditionally interpreted to stop children of undocumented immigrants from automatically becoming citizens just because they are born in the United States, claiming power no other president has asserted.

In the last days before a midterm congressional election that will determine the future of his presidency, Mr. Trump seems to be throwing almost anything he can think of against the wall to see what might stick, no matter how untethered from political or legal reality. Frustrated that other topics — like last week’s spate of mail bombs — came to dominate the news, the president has sought to seize back the national stage in the last stretch of the campaign.

Ad hoc though they may be, Mr. Trump’s red-meat ideas have come to shape the conversation and, he hopes, may galvanize otherwise complacent conservative voters to turn out on Tuesday. But he risks motivating opponents, as well, and he has put even some of his fellow Republicans on the spot as they are forced to take a position on issues they were not expecting to have to address.