Online used-car dealer Carvana Co. said it is aggressively cutting costs as demand from consumers remains under pressure and the company faces the prospect of an economic downturn.

Carvana—an early pandemic star that has struggled during the recovery—pledged in April to rein in expenses after it reported its first-ever quarterly-sales decline and said it would no longer provide guidance for the year. The company said it misjudged customer demand, planning for growth while rising interest rates and high inflation sapped business and made vehicle purchases unaffordable for many consumers. The following month it laid off 12% of its workforce.

Carvana said Thursday it is working to slash costs and improve efficiency across the business, including in its logistics, delivery, advertising and technology divisions. The company in May set a short-term goal of reducing its ratio of selling, general and administrative expenses to retail units sold to $4,000 by the fourth quarter. That figure—which excludes stock-based compensation, depreciation and amortization, as well as its recent acquisition of Adesa U.S., a used-car auction network—stood at $5,333 as of June 30.

Selling, general and administrative expenses dipped by about 1% as of June 30 compared with the previous quarter to $721 million. Carvana, which for years has focused on aggressive sales growth, said in a letter to shareholders Thursday that expense reduction is its number one financial objective.

Total retail units sold rose 9% in the second quarter from a year earlier, to 117,564. The company reported a net loss of $238 million, compared with a profit of $22 million a year earlier. Gross profit per unit—one of its preferred metrics—was $3,368 compared with $5,120 during the prior-year period.

The high price of used vehicles is weighing on demand across the industry, particularly among lower-income consumers, analysts said. The Manheim index of used car values dipped 1.3% in June from the prior month, but remains 9.7% higher than a year ago. Consumers also are facing higher costs in other areas of their budgets with inflation at a four-decade high. “Affordability is getting better, but consumers are a little bit less well off,” said Michael Baker, managing director at D.A. Davidson & Co.

Expenses are an aspect of the business that Carvana can control as it confronts an uncertain economic outlook, said Daniel Imbro, managing director at Stephens Inc. “Cost cuts are in focus until demand stabilizes,” Mr. Imbro said.

During the second quarter, investor demand for Carvana’s loans—a critical source of the company’s revenue—cooled as interest rates rose. The company typically packages most of its loans and sells them to investors through a process called securitization. But during the second quarter it didn’t bring to market an expected securitization of its nonprime loans made to riskier borrowers.

Carvana includes revenue from loan sales under a metric called other gross profit per unit. That figure declined 27% from a year earlier, to $1,854.

The company said in its shareholder letter that during the third quarter it expects to sell whole loans, rather than slicing them up into securities. Carvana has an agreement with Ally Financial Inc.,

a Detroit-based lender, to sell up to $5 billion of Carvana-originated loans through March 2023.

Carvana, which is still burning cash after 10 years in business, bolstered its liquidity. The company had just over $1 billion in cash and equivalents on its balance sheet as of June 30, up from $201 million a year earlier.

Carvana raised capital during the quarter, including $1.2 billion through a sale of common stock in late April. The company around the same time ran into problems selling debt to fund its $2.2 billion acquisition of Adesa. It ultimately received a lifeline from Apollo Global Management Inc., which agreed to buy half of the $3.275 billion in bonds at a 10.25% coupon.

Carvana had about $6.6 billion in long-term debt on its balance sheet as of June 30, up from just over $3 billion in the prior quarter, before the Adesa transaction closed.

Write to Kristin Broughton at Kristin.Broughton@wsj.com