WASHINGTON—The U.S. budget gap widened 38% in the first seven months of the fiscal year as federal spending outpaced tax collections.

The government ran a $531 billion deficit from October through April, the Treasury Department said Friday, compared with $385 billion during the same period a year earlier, a 38% increase. Federal outlays rose 8%, to nearly $2.6 trillion, while revenues increased 2%, to $2.04 trillion—a record for the seven-month period.

Part of the increase in the deficit was attributable to a shift in the timing of certain federal benefit payments, which made the deficit appear larger. If not for those timing shifts, the deficit would have risen 23% from the same period in fiscal year 2018.

Increased spending on the military, health care and interest on the debt contributed to higher outlays so far this fiscal year, which began Oct. 1. Meanwhile, individual tax receipts—including changes in tax refunds—increased 2.5% over the first seven months of the fiscal year, a senior Treasury official said Friday.

“Despite the fact that we have lower tax rates, that’s been more than offset by the increase in wages and increase in employment,” the official said.