President Trump directed the federal government on Tuesday not to count undocumented immigrants when allocating the nation’s House districts, a move that critics called a transparent political ploy to help Republicans in violation of the Constitution.

The president’s directive would exclude millions of people when determining how many House seats each state should have based on the once-a-decade census, reversing the longstanding policy of counting everyone regardless of citizenship or legal status. The effect would likely shift several seats from Democratic states to Republican states.

“There used to be a time when you could proudly declare, ‘I am a citizen of the United States,’” Mr. Trump said in a written statement after signing a memorandum to the Commerce Department, which oversees the Census Bureau. “But now, the radical left is trying to erase the existence of this concept and conceal the number of illegal aliens in our country. This is all part of a broader left-wing effort to erode the rights of Americans citizens, and I will not stand for it.”

The action directly conflicts with the traditional consensus interpretation of the Constitution and will almost surely be challenged in court, potentially delaying its effect if not blocking its enactment altogether. But it fit into Mr. Trump’s efforts to curb both legal and illegal immigration at a time when he is anxiously trying to galvanize his political base heading into a fall election season trailing his Democratic opponent.