The White House and congressional leaders have struck a budget deal that would suspend the debt limit until mid-2021, President Donald Trump and Democratic leaders announced Monday.

"I am pleased to announce that a deal has been struck with Senate Majority Leader Mitch McConnell, Senate Minority Leader Chuck Schumer, Speaker of the House Nancy Pelosi, and House Minority Leader Kevin McCarthy - on a two-year Budget and Debt Ceiling," Trump tweeted Monday evening, calling the agreement "a real compromise in order to give another big victory to our Great Military and Vets!"

I am pleased to announce that a deal has been struck with Senate Majority Leader Mitch McConnell, Senate Minority Leader Chuck Schumer, Speaker of the House Nancy Pelosi, and House Minority Leader Kevin McCarthy - on a two-year Budget and Debt Ceiling, with no poison pills.... — Donald J. Trump (@realDonaldTrump) July 22, 2019

The deal came several hours after a source close to the talks told NBC News that Treasury Secretary Steven Mnuchin and Pelosi, D-Calif., were close to a final agreement. A Pelosi aide told NBC News the pair spoke three times on Sunday and twice on Monday, with Schumer, D-N.Y., joining in on two of the calls. The four congressional leaders and Mnuchin then had a 5 p.m. conference call to resolve outstanding issues, the aide said.

The two-year agreement would suspend the debt limit until July 31, 2021, and put an end to automatic spending cuts that would have kicked in without a deal.

In a joint statement, Pelosi and Schumer said the deal “will enhance our national security and invest in middle class priorities that advance the health, financial security and well-being of the American people.”

They noted the deal “permanently ends the threat of the sequester,” or automatic spending cuts, and adds more cash for “critical domestic priorities.”

“Democrats have always insisted on parity in increases between defense and non-defense, and we are pleased that our increase in non-defense budget authority exceeds the defense number by $10 billion over the next two years,” they said.

The agreement also would increase funding to combat the opioid epidemic and would provide an additional $2.5 billion for the 2020 census to help "ensure everyone is counted," according to a Democratic breakdown of the agreement. Democrats had accused the Trump administration of trying to add a citizenship question to the census in an attempt to reduce the number of responses in immigrant communities, which would benefit Republicans. The administration dropped the bid earlier this month after a legal challenge.

The budget deal also says congressional leadership agreed there would be no "poison pills" or additional new riders on spending legislation unless agreed to on a bipartisan basis by the four leaders with the approval of the president, according to a Democratic summary.

“The House will now move swiftly to bring the budget caps and debt ceiling agreement legislation to the Floor, so that it can be sent to the President’s desk as soon as possible," they continued. "With this agreement, we can avoid the damage of sequestration and continue to advance progress for the people.”

McConnell, R-Ky., said in a statement that he intends to hold a vote on the deal before the August recess, adding he was "very encouraged" that the agreement "secures the resources we need to keep rebuilding our armed forces."

"This was our top objective: Continuing to restore the readiness of our armed forces and modernize our military to deter and defend against growing threats to our national security," he said.

McCarthy, R-Calif., said he was pleased the agreement would do away with automatic, across-the-board cuts to defense spending and policy riders on appropriations bills.

“While this deal is not perfect, compromise is necessary in divided government," he said and urged Pelosi to advance the deal.

Mnuchin had warned in recent weeks that the government could run out of money sooner than expected, in early September, which would put the U.S. in danger of defaulting on its debt for the first time if the debt ceiling were not increased before Congress left for its August recess.

The deal took shape as a traditional bipartisan budget agreement in which both sides would be unhappy with some aspects — a true compromise, the source close to the talks said. The proposed agreement would include parity in increases in domestic and defense spending and about $77.4 billion in spending offsets.

Sen. Patrick Leahy of Vermont, the top Democrat on the Senate Appropriations Committee, said he had "serious concerns" about the agreement, but added that it "will allow us to continue to make new investments in child care, combating the opioid epidemic, infrastructure and American communities. Also importantly, it will raise the debt limit for the next two years and stave off economic catastrophe. I will support the bill."

Trump spoke optimistically earlier in the day about the prospects for a deal and touted that it would boost military spending.

“We are, I think, doing very well on debt, if you look at debt limit, however you want to define that," Trump said. "But we're doing very well on that, and I think we're doing pretty well on a budget. Very important that we take care of our military. Our military was depleted and in the last two and a half years, we've un-depleted it, to put it mildly. We have made it stronger than ever before.”

Mnuchin told CNBC last Thursday that he'd been in regular contact with Pelosi in an effort to hammer out an agreement.

"I've been having daily conversations with the speaker," Mnuchin said. "I think that everybody is in agreement that we won't do anything that puts the U.S. government at risk in terms of our issue of defaulting. And I think that nobody wants a shutdown in any scenario."

Pelosi told reporters last week that she hoped to have a deal on the House floor by Thursday "so that we can send it in a timely fashion to the Senate so that they can go through their, shall we say, particularly senatorial process to get it done in time before they leave" for their recess.