One of President Donald Trump’s key messages during the 2016 campaign was touting his role as a successful business leader — someone who could make good deals for America and run the government more like a business.

To Trump, that seemed to mean having complete control over his employees and the ability to fire anyone at will. Since his inauguration, Trump has fired — or forced out — more than two dozen Cabinet-level staff members. But he and his aides have expressed frustration that they can’t do the same with about 1 million rank-and-file employees who work at the agencies he oversees.

The reason he can’t is simple: Unlike his employees at the Trump Organization, about a third of federal workers belong to unions. And those unions have negotiated certain job protections for workers, which includes a process that gives workers a chance to improve their job performance before they are terminated.

On Saturday, those unions won a major victory against the Trump administration’s efforts to weaken those protections. A federal judge invalidated key provisions in three executive orders the Trump administration issued in May, which had made it easier for agencies to fire federal workers and placed strict limits on union activities.

In her ruling, Judge Ketanji Brown Jackson of the US District Court for the District of Columbia said the executive orders were a clear violation of the Federal Service Labor-Management Relations Statute of 1978. Under that law, Congress gave federal employees the right to unionize and negotiate job contracts as a matter “of public interest.”

“The Court has concluded that many of the challenged provisions of the Orders at issue here effectively reduce the scope of the right to bargain collectively as Congress has crafted it, or impair the ability of agency officials to bargain in good faith as Congress has directed, and therefore cannot be sustained,” Jackson wrote in her decision.

The ruling comes at an otherwise rough time for government unions, which have taken multiple blows from Republicans and the courts in recent months. The Trump administration argued that these unions were making it too hard to fire bad federal employees. But union leaders said these protections were crucial to shield government workers from political attacks. Jackson ultimately decided that the president didn’t have the power to restrict union activity — a decision that shows why the president is not supposed to treat the government like a business.

“You’re fired” doesn’t work so well in Washington

There was a time when it was normal for a president to arrive at the White House and fire many civil servants who worked for past administrations. Even though federal workers had a few job protections, presidents had more discretion over personnel decisions until the middle of the 20th century, when members of both political parties began to worry that giving the president power to purge employee ranks caused instability and made the government less efficient. Some also worried that it damaged the public trust if the president could fire employees who blow the whistle on abusive government practices or boot those who hold different political views.

Presidents John F. Kennedy and Richard Nixon shared these concerns, and passed multiple executive orders that gave federal employees certain rights to unionize.

Later, in 1978, Congress gave federal workers the right to unionize under the law, as part of the Federal Service Labor-Management Relations Statute of 1978. But unlike workers in the private sector, unions that represent federal employees cannot negotiate over wages and work hours — only personnel practices, such as firings and suspensions. They also can’t call for a strike.

When Trump took office, he and his aides complained that it was too hard to fire the rank-and-file workers that the White House oversees. In his first State of the Union address in January, Trump made clear that he wanted his own purge.

“All Americans deserve accountability and respect — and that is what we are giving them. So tonight, I call on the Congress to empower every Cabinet secretary with the authority to reward good workers — and to remove federal employees who undermine the public trust or fail the American people,” he said.

While the argument in favor of firing career government employees was framed as an effort to shrink wasteful spending, the move seemed to be driven at least in part by politics. Trump and his allies have described a sinister “deep state” of career government employees who are out to take him down. His allies have backed up this claim by pointing out that an overwhelming number of federal workers donated to Hillary Clinton’s presidential campaign, and that many of them were hired during President Obama’s tenure.

“There are some reasons to believe a substantial number of people don’t want Trump to succeed,” Newt Gingrich, a former Trump adviser, told the New York Times in an interview in 2017. “Should the elected president of the United States have the ability to control the bureaucracy that actively opposed him?”

It’s no surprise, then, that Trump decided to try to exert more control over the fate of federal employees.

The executive orders, explained

The district court’s ruling this weekend involved four lawsuits filed against the Trump administration by 17 federal employees unions. The unions were challenging three executive orders Trump signed in May that rolled back labor protections for government workers.

One order made it easier to fire and reprimand federal employees. Depending on the agency, firing an employee for poor performance could take six months to a year, not including the appeals process. This order gave employees only 30 days to improve their job performance, instead of the current limit of up to 120 days. It also instructed agencies to consider a worker’s performance as more important than seniority during layoffs.

Another executive order directed agencies to spend less time negotiating contracts with labor unions and set a goal of no more than six months to reach an agreement. This was supposed to make the government “effective and efficient.”

A third order put strict limits on how much time employees in union leadership roles can spend on union activities during work hours. This is known as “official time,” and it can include helping other employees file complaints. The administration urged agencies to limit official time to 25 percent of an employee’s yearly work hours.

The administration said it has the legal authority to give such guidance to executive agencies that answer to the president. But the orders prompted immediate resistance from government unions.

The American Federation of Government Employees, which is the largest union involved in the lawsuits, said the efforts were a “direct assault on the legal rights and protections that Congress specifically guaranteed to the public sector employees across this country who keep our federal government running every single day.”

The court agreed, mostly.

Congress gave labor unions, not the president, power to negotiate contracts

Judge Jackson’s court ruling described the Trump administration’s defense of the orders as an attempt to do “verbal jujitsu” with the law. She seemed confounded by the argument that the administration had the power to interfere with union negotiations that are protected under federal law.

“There is no rational explanation for Defendants’ suggestion that Congress would have intended for the President to have the power to act in this fashion at all in regard to the matters that the FSLMRS specifically characterizes as negotiable. Quite frankly, it is hard to even imagine a rational statutory exception that is intentionally designed to swallow the rule,” she wrote.

Jackson ended up blocking most of the measures in the executive orders, only leaving a few in place, such as those that instruct agencies to consider imposing a contract if a union is delaying negotiations in bad faith.

A previous version of the article mistakenly stated the percentage of federal employees who are represented by labor unions. About a third of the nation’s 3.6 million federal workers are part of a collective bargaining unit.