(CNN) — Tesla has turned a profit as it nears the end of a long, trying year.

The company posted its third-quarter earnings Wednesday, with a net profit of $312 million. The company’s stock shot up more than 8% during after-hours trading.

“Q3 2018 was a truly historic quarter for Tesla. Model 3 was the best-selling car in the US in terms of revenue and the 5th best-selling car in terms of volume,” (TSLA) CEO Elon Musk said in a letter to investors.

The earnings exceeded Wall Street’s expectations. Analysts polled by Refinitiv predicted, on average, a loss of about 19 cents per share. Adjusted net income was $2.90 a share.

Since it went public in 2010, Tesla has posted a profit in only two quarters: once in 2013 and again in 2016. Meanwhile, the company has lost more than $4 billion. A slew of debt bills are due in the coming months, which has left some investors concerned.

Tesla’s performance last quarter, however, marks the strongest signal yet that the company is moving on from the beleaguered roll-out of the Model 3, its first car intended for the mass market.

Musk pledged earlier this year that Tesla would be in the black by the end of the year. Analysts had mixed reactions. But this week Tesla abruptly moved up its scheduled earnings, which many took as a sign the company was eager to show off its quarterly profit.

The big question for Wall Street now is whether Tesla can maintain the momentum and consistently bring in more than it spends.

Wednesday’s earnings report marks Tesla’s first since Musk was ousted from the chairman role after he and the company reached a settlement with the Securities and Exchange Commission.

The billionaire drew regulators’ scrutiny after he tweeted in August that he was locking down a deal to take Tesla off the stock market at $420 per share. The tweet triggered a stock surge. The SEC fined Tesla and Musk $20 million.

© Copyright 2018 CNN. All Rights Reserved. This material may not be published, broadcast, rewritten or redistributed.