SEOUL — Hyundai Motor swung to a 336 billion won ($297 million) net loss for the July-September quarter, as costs related to engine quality issues and recalls smashed what would otherwise have been strong earnings.

The automaker said it booked 2.1 trillion ($1.9 billion) won to cover charges related to engine defects that increased the risk of stalling and fire.

“Third-quarter results reflect engine-related provision expenses as the company took preemptive measures to ensure customer safety and cover any possible future increase in quality-related expenses,” Hyundai said in a statement on Monday.

“We sincerely apologize to our shareholders and investors for having repeated quality cost issues over three quarters since 2018,” an executive told an earnings briefing.

The years-long quality problems have cost Hyundai and its affiliate, Kia, nearly $5 billion and left the pair subject to a probe by U.S. authorities over the manner of their recalls.

Operating loss for the third quarter was 314 billion won ($277 million). Excluding quality costs, the figure would have been 1.8 trillion won ($1.6 billion) profit. Revenue rose 2.3 percent on year to 27.6 trillion won ($24.4 billion).

Analysts said the operating loss was not as deep as expected as Hyundai enjoyed solid sales in the quarter backed by increased demand in the U.S. and emerging markets such as India.