WASHINGTON—President Donald Trump stunned Republicans on Wednesday when he overrode pleas from GOP congressional leaders and sided with Democrats on a proposal to attach emergency aid for Hurricane Harvey victims to measures to keep the government funded and its borrowing limit suspended until mid-December.

Mr. Trump’s decision to strike a deal with Democrats upended the partisan alliances that have long set the boundaries of congressional policy-making, opening up new possibilities for bipartisan deal-making if Democrats...