A U.S. judge ordered the Commerce Department to reinstate a Chinese-American hydrologist it had fired over many of the same allegations in a failed spy case.

Sherry Chen was correct to assert she had been the “victim of a gross injustice” when the department fired her in 2016, according to a ruling last week by the Merit Systems Protection Board.

Michele Szary Schroeder, a judge for the MSPB, which is an independent body that hears appeals from federal employees over personnel decisions, wrote that the officials involved in deciding Ms. Chen’s fate were “more concerned about being right than doing the right thing.” She added: “Based on the unyielding nature of their testimony, I would not have been surprised if they rejected that 2 + 2 = 4.”

Following a hearing and examination of evidence, Judge Schroeder ordered the Commerce Department to give Ms. Chen her job back and to make up for lost wages after finding that nearly every reason it had given for firing her wasn’t supported by the facts.

A spokesman for the Commerce Department said it would appeal the decision. The department is the parent agency of the National Weather Service’s Ohio River Forecast Center, where Ms. Chen worked to predict floods.