The U.S. Postal Service on Thursday reported a $5.2 billion quarterly loss and said it was nearly out of cash and likely to exhaust its government credit line in coming months.

The agency said the loss was its widest since it began releasing quarterly financials in 2007. But Postmaster General Patrick Donahoe said the Postal Service would do whatever it takes to maintain its operations, even if that means defaulting on a second multibillion-dollar retiree obligation in as many...