New York (CNN Business) 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, by far its largest ever. The company's stock shot up around 10% 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 $6 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.

"Tesla had a very strong Q3, blowing past most expectations. Kudos to Elon Musk and team for surprising nearly everyone. Now, the question remains -- can Tesla make this a habit, or this this a blip on the radar?" said Akshay Anand, executive analyst for Kelley Blue Book, in an emailed statement.

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 last month. He was given 45 days to exit the role.

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 and ordered to company to install two new independent board members.

Tesla's tough year

Tesla has been plagued by production issues with its Model 3 sedan. Musk promised to be churning out 5,000 cars per week by the end of 2017. It finally hit that goal over the summer.

The delay didn't come without costs. Customers canceled orders, and the negative narrative was exacerbated by a slew of scandals surrounding Musk.

He has fired off late-night tweets and brushed off analysts on a corporate earnings call. He insulted and then was sued by a man who was working to rescue boys trapped in a cave in Thailand, and he's sparred with journalists and investors he believed were unfair to him.

Musk's latest controversy came to a head last month, when it looked like he would fight the SEC's lawsuit over his pledge to take Tesla private, a pledge he reneged on shortly after he made it.

All that has lent for a rocky year for Tesla' stock. And it's still well-below it's all-time high of nearly $390 per share. Tesla's stock after Wednesday's close was $288.50.

Better days ahead?

The company's report comes one day after a longtime Tesla bear, Andrew Left of Citron Research, delivered an about face in blog post. He declared Tesla was "destroying the competition."

"Citron is long Tesla as the Model 3 is a proven hit and many of the Tesla warning signs have proven not to be significant," Left wrote.

Tesla's stock climbed up more than 12% on Tuesday, egged on by Left's post and news that earnings would go up sooner than expected.

The conference call Wednesday was a welcome reprieve for Tesla executives.

Musk has long faced detractors who have berated him for failing to meet his deadlines. But Musk happily touted the results on Wednesday, promising it was a sign of more to come.

"This quarter was an important step toward" sustained profitability, Musk said, adding he's "excited about about what lies ahead."

Rebecca Lindland, executive analyst for Kelley Blue Book, praised the latest earnings report and expressed optimism that Tesla will benefit from coming changes.

"Tesla rewarded investor confidence by finally booking a profit in the third quarter, despite an array of self-inflicted wounds," she said in an emailed statement. "A new chairman and independent board members may provide management guidance and perspective, which makes this result sustainable in the long term."