WASHINGTON/ABOARD AIR FORCE ONE (Reuters) - President Donald Trump forged a surprising deal with Democrats in Congress on Wednesday to extend the U.S. debt limit and provide government funding until Dec. 15, embracing his political adversaries and blindsiding fellow Republicans in a rare bipartisan accord.

Trump, living up to his reputation for unpredictability, met at the White House with congressional leaders from both parties and overruled Republicans and U.S. Treasury Secretary Steven Mnuchin, who wanted a longer-term debt-limit extension rather than the three-month Democratic proposal the president embraced.

“We could have done a one-year deal today,” Mnuchin told reporters aboard Air Force One later in the day en route back to Washington from an event in North Dakota where Trump spoke about taxes.

Mnuchin said Trump chose a short-term deal to keep his options open on possibly raising military funding later this year, suggesting a longer-term government funding deal might have blocked that.

Trump is very focused on military spending, “particularly with what’s going on in North Korea and other parts of the world today,” Mnuchin said. “The president wasn’t willing to give up his need for additional military spending.”

If passed by the Republican-led Congress, the three-month agreement would avert an unprecedented default on U.S. government debt, keep the government funded at the outset of the fiscal year beginning Oct. 1 and provide aid to victims of Hurricane Harvey.

“It was a really good moment of some bipartisanship and getting things done,” top Senate Democrat Chuck Schumer said.

Less than an hour before the meeting, Republican House of Representatives Speaker Paul Ryan had called the Democratic proposal that Trump later embraced a “ridiculous and disgraceful” idea that would “play politics with the debt ceiling.”

Even with the three-month extension of the debt limit, a Senate Republican aide told reporters that nothing in the tentative deal would stop the Treasury Department from using its powers to extend the deadline, depending on revenue flow. In the past, the debt limit deadline has been extended for several months under those powers.

‘NEEDED TO COME TOGETHER’

Senate Majority Leader Mitch McConnell, overridden by Trump during the meeting, said he would bring the deal to the Senate floor for a vote.

“The president can speak for himself, but his feeling was that we needed to come together, to not create a picture of divisiveness at a time of genuine national crisis,” McConnell told reporters.

The agreement was an uncommon instance of bipartisan compromise since Trump took office in January. Washington has suffered through bitter partisanship that has at times left the U.S. capital dysfunctional under Trump and his Democratic predecessor, Barack Obama. Trump had tangled repeatedly with Schumer and top House Democrat Nancy Pelosi.

Slideshow ( 10 images )

“We had a very good meeting with Nancy Pelosi and Chuck Schumer,” Trump, a wealthy businessman who as a candidate touted his deal-making skills, told reporters aboard Air Force One, without mentioning McConnell or Ryan, with whom he has had fraught relations.

“We agreed to a three-month extension on debt ceiling, which they consider to be sacred, very important. Always we’ll agree on debt ceiling, automatically because of the importance of it,” Trump said.

Conservative groups were aghast, accusing Trump of caving in to the Democrats rather than insisting on spending cuts to accompany the debt ceiling increase, and some hard-line Republicans expressed opposition to it.

Slideshow ( 10 images )

Republican leaders and Mnuchin pushed in the meeting for an 18-month debt limit hike, then floated six months, but Pelosi and Schumer held firm to their three-month proposal and Trump sided with them, according to people familiar with the meeting.

The party in power, in this case Republicans, often argues for the longest debt limit increase as possible for two reasons. First, it protects members of Congress from casting multiple votes on the politically unpopular legislation over a short period of time, especially in the run-up to the 2018 congressional elections. Second, it helps stabilize markets.

For minority Democrats, whose votes are needed to pass debt ceiling increases, they could potentially use the debt limit vote later in the year as leverage to win concessions on a tax overhaul package that Trump badly wants to advance.

Even though Republicans control the White House and both chambers of Congress, Trump has yet to win passage of any major legislation, with Democrats typically united against him.

The House on Wednesday approved roughly $8 billion in initial emergency aid for relief and rebuilding after Hurricane Harvey, which tore into Texas on Aug. 25, with the measure now going to the Senate.

“Our No. 1 priority was getting funding for Harvey,” Mnuchin said. “To get the funding for Harvey, we needed to extend the debt limit.”

STOCKS, DOLLAR RISE

U.S. shares rose and the dollar gained against the safe-haven Japanese yen as word of the deal helped mitigate investor concerns about North Korea and a major hurricane barreling toward Florida. The news also lifted the yield on benchmark 10-year U.S. Treasury notes US10YT=RR after it had fallen to a near 10-month low at 2.054 percent.

The Treasury Department has said the ceiling must be raised in the next few weeks. If not, the government would be unable to borrow more money or pay its bills, including its debt payments. That could hurt the U.S. credit rating, cause financial turmoil, harm the economy and possibly trigger a recession.

Representative Kevin Cramer, a Republican from North Dakota, was aboard Air Force One when he heard about the short-term deal. He told reporters on the plane: “I will tell you that I gasped when I heard it.”

He said the deal would be a “tough sell” for House Republicans but that some would “warm up to the idea” when they learned more about it.