WASHINGTON — Congressional negotiators reached an agreement late Sunday on a broad spending package to fund the government through the end of September, alleviating fears of a government shutdown later this week, several congressional aides said.

Congress is expected to vote on the package early this week. The bipartisan agreement includes $12.5 billion in new military spending and $1.5 billion more for border security, a major priority for GOP leaders in Congress.

The agreement follows weeks of tense negotiations between Democrats and Republican leaders after President Donald Trump insisted that the deal include funding to begin building a wall along the U.S.-Mexico border. Trump eventually dropped that demand, leaving Congress to resolve lingering issues over several unrelated policy measures.

The new border-security money comes with strict limitations that the Trump administration use it only for technology investments and repairs to existing fencing and infrastructure, the aides said.

“This agreement is a good agreement for the American people, and takes the threat of a government shutdown off the table,” said Senate Minority Leader Charles Schumer of New York. “The bill ensures taxpayer dollars aren’t used to fund an ineffective border wall, excludes poison pill riders, and increases investments in programs that the middle class relies on, like medical research, education and infrastructure.”

The agreement also includes several policy victories for Democrats, whose votes will be necessary to pass the measure in the Senate. Democrats fought to include $295 million to help Puerto Rico continue making payments to Medicaid, $100 million to combat opioid addiction, and increases in energy and science funding that Trump had proposed cutting. If passed, the legislation will ensure that Planned Parenthood continues to receive federal funding through September.

The package includes $61 million to reimburse local law enforcement agencies for the cost of protecting Trump when he travels to his residences in Florida and New York, a major priority for the two New York Democrats involved in the spending talks, Schumer and Rep. Nita Lowey.

Among the bipartisan victories is a decision to permanently extend a program that provides health care coverage for coal miners and $407 million in wildfire relief for western states.

“The agreement will move the needle forward on conservative priorities and will ensure that the essential functions of the federal government are maintained,” said Jennifer Hing, a spokeswoman for House Appropriations Committee Chairman Rodney Frelinghuysen, a New Jersey Republican.

House Republicans have struggled in recent weeks to keep their members focused on spending as White House officials and conservatives pressed leaders to revive plans for a vote on health care legislation. The health care fight became tangled last week in spending talks as leaders worried that forcing a vote to repeal the Affordable Care Act risked angering Democrats whose votes are necessary to avoid a government shutdown.

Leaders worked last week to determine whether the House has enough votes to pass a revised health care bill brokered by the White House, the head of the conservative House Freedom Caucus and a top member of the moderate Tuesday Group.

House Speaker Paul Ryan of Wisconsin and his top lieutenants announced Thursday that they did not have sufficient votes to be sure the measure would pass but vowed to press on.

“We’re still educating members,” House Majority Leader Kevin McCarthy of California told reporters after a late-night health care meeting last week. “We’ve been making great progress. As soon as we have the votes, we’ll vote on it.”