Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

Congress sent President Donald Trump a multi-billion dollar poke in the eye Monday, refusing to slash medical spending as Trump proposed and instead giving the National Institutes of Health a $2 billion raise.

The budget agreement, finalized in the wee hours of Monday morning, also defies Trump’s demand for cuts to NASA’s earth science program, which the administration had targeted as part of a wider promise to cut climate change research. And it provides $103 million to fight the opioid abuse epidemic — an area of rare bipartisan agreement that even Trump supports.

The new budget proposal, which needs votes in the House and Senate, would keep the government running until October, when the 2018 budget is supposed to kick in.

Trump had proposed slashing NIH by $1.2 billion for the rest of 2017 to help pay for his proposed increases in defense spending. Instead, Congress gave the NIH an extra $2 billion for the next 6 months, bumping its total 2017 budget to $34 billion.

Oklahoma Rep. Tom Cole, a Republican who chairs the appropriations subcommittee that oversees NIH funding and who sits on the budget committee, said funding medical research is something Republicans and Democrats agree on easily.

Related: Congressional Leaders Reach $1 Trillion Agreement to Avert Shutdown

“We doubled NIH funding in the late 1990s and early 2000s and then we were flat for a dozen years,” Cole told a seminar on biodefense Monday morning. The result was a giant cut in proposed medical research projects that got paid for, he said.

“Instead of funding one in three grants we fell to funding one in six,” Cole said.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

He said the agency, as well as the Centers for Disease Control and Prevention, need regular increases, not cuts.

“The bill includes a total of $73.5 billion for HHS (the Health and Human Services Department), an increase of $2.8 billion above last year’s enacted level and $3.8 billion above the previous Administration’s budget request,” the House Appropriations committee said in a statement.

“It includes specific increases for research related to Alzheimer’s disease, the brain, antibiotic resistance, and the Precision Medicine Initiative. The bill also provides a general increase to all NIH Institutes and Centers to continue progress in developing new treatments and cures,” it added.

Specifically, the bill:

Gives the National Cancer Institute nearly $5.4 billion, including $300 million to the Obama administration’s Cancer Moonshot program

Provides $4.9 billion to the National Institute of Allergy and Infectious Diseases

Raises Alzheimer’s research funding by $400 million, to $1.4 billion

Gives $120 million to former president Barack Obama’s BRAIN initiative

Gives $3.2 billion to the National Heart, Lung, and Blood Institute

Allocates $57 million to prepare for an influenza pandemic

Gives CDC $112 million for “an evidence-based opioid drug overdose prevention program” and $50 million to the Veterans Health Administration for opioid and substance abuse treatment.

The new 2017 budget also preserves the $101 million Teen Pregnancy Prevention program that Trump proposed cutting in half.

It also sets aside $32 million for the United Nations Population Fund (UNFPA). Trump’s State Department earlier this year said it would stop giving any money to UNFPA, which got $69 million from the U.S. last year, so the bill provides for the money to go to other global health programs instead.

Related: Proposed Trump Budget Cuts Would Devastate Medical Spending, Experts Say

The Centers for Disease Control and Prevention gets a small increase, also.

“The agreement includes a total of program level of $7.3 billion for the CDC — $22 million above the fiscal year 2016 enacted level. This includes $6.3 billion in appropriated funds, as well as $891 million in transfers from the Prevention and Public Health Fund,” the Appropriations summary said.

A GOP bill designed to replace as much of the Affordable Care Act as possible had targeted the Prevention and Public Health Fund, which accounts for 12 percent of the CDC budget. But Congress joined Trump in doing everything possible to starve the 2010 Affordable Care Act. “The bill provides no new funding for Obamacare,” the committee said.

And it returns the U.S. to a focus on “abstinence only” education, which many studies have shown is not effective in reducing teen pregnancies or stopping the spread of disease.

Related: Teen Birth Rate Not Low Enough, CDC Says

“The legislation also increases funding for sexual risk avoidance programs for teens (formerly known as abstinence education) by 50 percent,” the committee said.

NASA gets a 1.9 percent increase, with $19.5 billion to spend before October, including $1.9 billion for earth science, and keeps the NASA education office running despite Trump administration proposals to cut it.

The budget also gives a small raise to climate change research. The National Oceanic and Atmospheric Administration’s (NOAA) Office of Oceanic and Atmospheric Research gets a 3.5 percent increase to $478 million.

The fight is not over. Trump has indicated he wants to cut overall health spending, including NIH, by 20 percent for 2018.