President Donald Trump's fellow Republicans rebuked him on Wednesday after his threat to shut down the U.S. government over funding for a border wall rattled markets and cast a shadow over congressional efforts to raise the country's debt ceiling and pass spending bills.

"I don't think anyone's interested in having a shutdown," the top Republican in Congress, House of Representatives Speaker Paul Ryan, told reporters on Wednesday in Hillsboro, Oregon, where he visited an Intel factory.

Ryan said building a wall along the country's border with Mexico to deter illegal immigration was necessary, but added that the government did not have to choose between border security and shuttering operations.

Trump in a speech on Tuesday evening threatened a shutdown if Congress does not agree to fund constructing the wall, a signature promise of his presidential campaign, which added a new complication to Republicans' months-long struggle to reach a budget deal.

After Mexico rejected a chief part of Trump's promise — that it would pay for the wall — the president said the United States would fund it initially and be repaid by its southern neighbor. Lawmakers, including many Republicans, have not made that funding a top priority, as some question if a wall is necessary.

Congress will have about 12 working days when it returns on Sept. 5 from its summer break to approve spending measures to keep the government open, while also facing a looming deadline to raise the cap on the amount the government may borrow. Both are must-approve measures.

U.S. stocks and the dollar weakened and investors pivoted to the safety of U.S. Treasury securities on Wednesday after Trump's threat. The S&P 500 index closed about 0.3 percent lower, the Dow Jones Industrial Average was down by 0.4 percent and the Nasdaq Composite Index slid 0.3 percent.

Ryan suggested Congress would need to approve a short-term extension, or continuing resolution, of current funding levels so that the Senate could have more time to pass a full spending bill. That would push the budget battle to later in the year and could in turn delay attempts at tax reform, another signature Trump campaign issue.