WASHINGTON — The Trump administration violated the law in withholding security assistance aid to Ukraine, a nonpartisan federal watchdog agency said on Thursday, weighing in on a decision by President Trump that is at the heart of the impeachment case against him.

The Government Accountability Office said the White House’s Office of Management and Budget violated the Impoundment Control Act when it withheld nearly $400 million for “a policy reason,” even though the funds had been allocated by Congress. The decision was directed by the president himself, and during the House impeachment inquiry, administration officials testified that they had raised concerns about its legality to no avail.

“Faithful execution of the law does not permit the president to substitute his own policy priorities for those that Congress has enacted into law,” the G.A.O. wrote. “The withholding was not a programmatic delay.”

The impoundment law limits a president’s power to withhold money that has been allocated by Congress, requiring that he secure approval by the legislative branch if he wishes to do so.

The White House budget office promptly rejected the report’s conclusions.

“We disagree with G.A.O.’s opinion,” said Rachel Semmel, a spokeswoman for the budget office. “O.M.B. uses its apportionment authority to ensure taxpayer dollars are properly spent consistent with the president’s priorities and with the law.”

The report, on its own, does not result in any action, although its release just as Mr. Trump’s impeachment trial is getting underway is certain to fuel additional questions about the impact of his actions.

Senator Chris Van Hollen, Democrat of Maryland, a vocal critic of Mr. Trump’s decision to block the funds, on Thursday called the G.A.O. report a “bombshell legal opinion.” It “demonstrates, without a doubt, that the Trump Administration illegally withheld assistance from Ukraine and the public evidence shows that the president himself ordered this illegal act,” he wrote on Twitter.

This is a developing story. Please check back for updates.