The government just shut down. Here’s how it happened.

Time ran out.

WASHINGTON, DC - JANUARY 19: The U.S. Capitol is seen as lawmakers work to avert a government shutdown January 19, 2018 in Washington, DC. A continuing resolution to fund the government has passed the House of Representatives but faces a stiff challenge in the Senate. (Photo by Aaron P. Bernstein/Getty Images)
WASHINGTON, DC - JANUARY 19: The U.S. Capitol is seen as lawmakers work to avert a government shutdown January 19, 2018 in Washington, DC. A continuing resolution to fund the government has passed the House of Representatives but faces a stiff challenge in the Senate. (Photo by Aaron P. Bernstein/Getty Images)

Many federal government agencies and services officially shut down midnight Saturday, after the Senate rejected a short-term spending bill that would have funded the government through Feb. 16.

The first government shutdown since 2013 came after months of confusing and contradictory statements by President Donald Trump, often on Twitter, and an unwillingness by Republicans to include legislation to protect “DREAMers.” Roughly 800,000 undocumented immigrants who have lived in the U.S. since they were kids face deportation without a bill that would let them remain and work in the country.

Hours before the midnight deadline, Senate Minority Leader Chuck Schumer (D-NY) went to the White House to push for a short-term agreement. Schumer had been pushing for a continuing resolution of just a few days to give both parties time to strike a bipartisan immigration bill. Both Schumer and Trump claimed they made progress on the outstanding issues during the meeting — but they were unable to strike a deal before the midnight deadline.

And while Republicans attempted to place blame on Democrats for the shutdown, several GOP Senators also refused to support the bill, which passed the House Thursday night, unwilling to support a measure that simply kicks the can down the road. Ultimately, Republicans were unable to secure support for their plan within their own party.

In a statement released just before midnight, the White House called Democrats “obstructionist losers.”

By midnight, everything from national parks and Smithsonian museums to the processing of applications for passports and visas will stop operating because those departments will no longer have funding. While the shutdown does not affect what are considered “essential” services including parts of the military, the Department of Defense, airport security, and law enforcement agencies, as many as 850,000 federal workers will be ordered to stop working.

The drama unfolded less than a week after a federal judge temporarily blocked the Trump administration from ending the Obama-era program called Deferred Action for Childhood Arrivals (DACA) in March — rolling back deportation protections for that large undocumented population known as DREAMers and their ability to work in the U.S. The ruling still allowed the administration to continue blocking new applications by eligible immigrants who have never applied for the program before while allowing current beneficiaries to renew their DACA status.

Democratic Senators are demanding a bill that provides permanent protections for DREAMers and are willing to pair it with funding for enhanced border security. Democrats have been unwilling to cede to Trump’s demand for a $20 billion wall and wholesale changes to the legal immigration system favored by hardliners.

Desperate for Democratic support on the short-term bill, Republicans proposed six years of funding for the Children’s Health Insurance Program (CHIP) — a key program that provides health insurance coverage for roughly 9 million kids. Despite pleas from Democrats and state governments, Republicans had previously declined to provide long term funding for the program, which expired in September.

A number of Democrats, however, indicated they would not support a spending bill unless it included a permanent legislative fix for DACA. In response, Republicans attempted to change the narrative surrounding the government shutdown by providing a false choice: Either Democrats support their plan that would potentially destroy the lives of a large vulnerable population or they value “illegals” more than sick kids and the military.

The president’s son Donald Trump Jr. wrote on Twitter Friday morning: “Democrats willingness to shut down the govt and cut off children’s insurance and US military salaries at home and abroad for illegal immigrants tells you all you need to know about Democrats.”

President Trump, however, at times veered away from the talking points of his party and his own administration. Trump took to Twitter on Thursday writing: “CHIP should be part of a long term solution, not a 30 day, or short term, extension!”

The tweet contradicted a statement from the Office of Management and Budget, which claimed the administration supported the bill’s multiyear funding extension of CHIP.

There were other disagreements that led to the government shutdown: Both Democrats and Republicans want to lift spending caps but had different priorities. Republicans wanted to increase defense spending, while Democrats called for an equal boost for domestic spending.

Last week, Trump was presented a bipartisan compromise that would have protected DREAMers in exchange for funding for border security and some changes to the legal immigration system. But blew-up the deal during a meeting with lawmakers where he allegedly made racist remarks, asking why America should accept immigrants from “shithole countries” like El Salvador, Haiti, and countries in Africa. He suggested accepting more immigrants from Norway instead.

But Saturday morning’s government shutdown has been months in the making. This is how it happened.

May 23: The Trump administration unveiled its fiscal 2018 budget proposal, which includes a $54 billion increase in defense spending, a $2.6 billion down payment for the Mexican border wall, and $1.4 billion for charter school voucher programs but dramatically cuts funding for most other agencies and slashes many programs assisting low-income and marginalized communities at home and abroad. Major cuts to core agencies include a 33 percent State Department decrease, a 31 percent decrease for the Environmental Protection Agency, 21 percent decreases for the Agricultural and Labor Departments, 18 percent decrease for the Department of Health and Human Services, and a 16 percent decrease for the Commerce Department.

The president’s budget proposal acts as more of a wishlist and is typically changed by Congress.

September 5: The Trump administration announced in six months it will end Deferred Action for Childhood Arrivals (DACA) — a program created by the Obama administration allowing 800,000 undocumented immigrants who came to the United States as children some protection against  deportation.

Attorney General Jeff Sessions falsely claimed the program was an “unconstitutional exercise of authority by the executive branch.” The decision also ran counter to the views of many prominent Republicans, including House Speaker Paul Ryan who implored the president not to end the program during an interview on his hometown radio station four days earlier. But Ryan, among other party members, quickly changed his views on DACA and offered his support for the decision after it was announced.

September 13: News broke that Trump had brokered a deal with Democrats to protect DREAMers in exchange for a border security package that did not include funding for Trump’s U.S.- Mexico border wall. However, Trump and his press secretary Sarah Huckabee Sanders quickly took to Twitter saying no deal had been reached.

Trump said on Twitter the next morning that “massive border security” would have to be agreed upon for such a deal to take place. Then minutes later, he asserted a wall would be built, which was followed by another Tweet claiming deporting DREAMers who “have been in our country for many years through no fault of their own” wasn’t a desirable outcome for any party.

September 30: Following failed attempts by Republicans to repeal Obamacare over the summer, the Children’s Health Insurance Program — which provides health coverage for kids from families whose income exceeds Medicaid qualification levels but who need help affording insurance — expired. CHIP, which was created in 1997, provides insurance for roughly 9 million kids and costs the federal government a little over $14 billion per year. In some states, funding for the program will run dry in January.

October 1: The start of fiscal year 2018 and the deadline for Congress and the president to pass 12 appropriations bills that determine federal spending for discretionary programs — including defense, environmental protection, education, job training, border security, scientific research, transportation, economic development, law enforcement, and international assistance, among others.

Congress subsequently passed a series of continuing resolutions, temporarily extending 2017 funding levels until those spending bills are passed, avoiding a shutdown of many important, “non-essential” federal government agencies and services.

October 4: The Senate passes a bipartisan bill that would have extended funding for CHIP for five years. However, a House bill to do the same hit a snag after Republicans tried to offset the cost of the program by taking money from Medicare and the Affordable Care Act.

October 20: The Senate passed a fiscal 2018 budget resolution that expanded the federal deficit by $1.5 trillion over 10 years to pay for the Republican tax bill that disproportionately benefited wealthy individuals and large corporations. The Republican Senate majority passed the budget resolution through reconciliation, a procedure allowing it to pass legislation with only 51 votes. No Democrats would vote for the bill.

Republicans would spend the next two months largely ignoring the work of funding the government — instead focusing their attention on their tax plan.

December 20: Republicans passed the tax overhaul that disproportionately benefits wealthy people and major corporations without providing any funding for CHIP. Sens. Lamar Alexander (R-TN) and Susan Collins (R-ME) said they did not expect to appropriate long-term funding for CHIP until 2018. The Center for Children and Families published a report that said, if Congress failed to enact a long-term solution for CHIP, 1.9 million children would lose coverage by the end of January.

December 21: Following a short-term spending bill just two weeks earlier, Congress passed its latest continuing resolution, allowing the government to continue operating under the fiscal 2017 budget through January 19. The stopgap measure allowed Republicans to avoid an embarrassing government shutdown days after passing their coveted tax bill but left a number of important issues on the table for the next year, including a solution for DACA.