Rising tax revenue, public spending cuts and big payments to the Treasury from government-backed mortgage companies helped the government take in $117 billion more last month than it paid out, the U.S. Treasury said on Thursday.

Analysts polled by Reuters had expected a surplus of $39.5 billion.

June’s surplus was the largest on record for that month.

While the government is still $510 billion in the red with three months to go in the fiscal year, June’s big surplus will buy it time before it runs up against the limit on borrowing set by Congress. Analysts expect the Treasury to hit the debt ceiling by early November.