WASHINGTON >> A federal judge on Thursday ordered six federal agencies to rehire thousands of workers with probationary status who had been fired as part of President Donald Trump’s government-gutting initiative.

Ruling from the bench, Judge William H. Alsup of U.S. District Court for the Northern District of California went further than a previous ruling. He found that the Trump administration’s firing of probationary workers had essentially been done unlawfully by fiat from the Office of Personnel Management, the government’s human resources arm. Only agencies themselves have broad hiring and firing powers, he said.

He directed the Treasury and the Veterans Affairs, Agriculture, Defense, Energy and Interior departments to comply with his order and offer to reinstate any probationary employees who were improperly terminated. But he added that he was open to expanding his decision later to apply to other agencies where the extent of harms had not been as fully documented yet.

His order stemmed from a lawsuit brought by federal employee unions that challenged the legality of how those agencies went about firing probationary workers en masse. The unions argued that those workers were swept up in a larger effort by Trump and his top adviser, Elon Musk, to arbitrarily ravage the federal government and demoralize its employees.

Alsup said he was convinced that federal agencies followed a directive from senior officials in the Office of Personnel Management to use a loophole allowing them to fire probationary workers by citing poor performance, regardless of their actual conduct on the job. He concluded that the government’s actions were a “gimmick” intended to expeditiously carry out mass firings.

“It is a sad day when our government would fire some good employee and say it was based on performance when they know good and well that’s a lie,” he said.

“It was a sham in order to try to avoid statutory requirements,” he added.

He also extended his restraining order issued last month blocking the Office of Personnel Management from orchestrating further mass firings. But before handing down his ruling Thursday, Alsup was careful to make sure the lawyers representing the unions understood its limits.

Agencies planning to conduct large-scale layoffs, known as a “reduction in force,” can still proceed in accordance with the laws that govern such processes — meaning that the reprieve for workers may only be temporary. The Office of Personnel Management had set a deadline of Thursday for agencies to submit reduction in force plans.

“If it’s done right, there can be a reduction in force within an agency, that has to be true,” Alsup said.

As the Trump administration continues to contest the judge’s order, a substantial portion of the hearing Thursday also focused on the ways the government has moved to circumvent the courts and sideline workers by any means available.