In the midst of its most chaotic year yet--which is saying a lot--Tesla might have finally righted its ship. 

The company announced its third-quarter earnings on Wednesday, posting a $312 million profit. It's only the third quarterly profit in the company's history, and by far the biggest, surpassing its previous high of $22 million. 

The company earned $6.92 billion in revenue in the quarter, more than double the $2.98 billion it posted in the same quarter last year. That largely was due to the number of vehicles Tesla was able to deliver: 83,000, an all-time high for the firm--and as many as it delivered in all of 2016.

The company's profit amounts to $2.90 per share. Wall Street had predicted a loss of $0.14 per share. Tesla's stock surged more than 8 percent in after-hours trading on Wednesday.

Musk sounded upbeat during the company's earnings call, answering questions straightforwardly without the defensiveness he's shown when speaking with analysts and reporters at other times this year.

The company was initially penciled in for an November 7 earnings call, but announced on Tuesday that it would be reporting its numbers the following day. Explanations for the move were varied, with some positing that CEO Elon Musk wanted to get the quarter's poor results out of the way, and others predicting good results that Musk didn't want to see get lost in the early November election news cycle.

It would appear the latter is true. And now, perhaps the company can finally focus on what every company should focus on: staying profitable. 

Even before the earnings were released, several analysts changed their tune on Tesla on Tuesday based on their own analyses. JMP Securities upgraded the stock to an "outperform" rating, and market watcher Andrew Left, who has been advising shorting the company for two years and is currently suing Tesla over Musk's misleading tweets, revealed he was going long on the company's stock. "Like a magic trick, while everyone is focused on Elon smoking weed, he is quietly smoking the whole automotive industry," Left wrote.

There is currently $9.9 billion riding against Tesla, making it the most shorted stock besides Apple.

Of course, there is reason to doubt the electric car company. Musk had to step down as board chairman and pay a $20 million fine as the result of a settlement with the Securities Exchange Commission earlier this month. The SEC was suing Musk over his Twitter comments in August, in which he falsely claimed he'd secured the funding necessary to take Tesla private.

The company has also seen an exodus from its senior-level positions in recent months. Chief accounting officer Dave Morton announced his resignation in September after just a month on the job. That same month, head of human resources Gabrielle Toledano announced her departure and head of communications Sarah O'Brien left her role. The company's VP of finance both departed this year as well. A total of 58 executives left the company between September 2017 and September 2018, according to a list compiled by Tesla short seller Jim Chanos.

But maybe, just maybe, the company's biggest troubles are behind it.

The thing with Tesla is this: It makes a great product. Its customers--those who have actually received their orders, at least--often love it. The company continually rolls out software upgrades to keep users up to date. The vehicles, being electric, limit carbon emissions and give customers a sense of satisfaction that their luxury vehicles are doing some good for the world.

For those reasons, few have doubted what Tesla could be in its best-case scenario. The qualms have almost always been related to execution. Musk has done little in recent months to quell those doubts, creating embarrassing distractions by calling a cave diver "pedo" on Twitter or smoking pot on Joe Rogan's podcast.

But maybe Tesla, finally, is on its way to fulfilling its potential. The company has taken a significant step. Now, it has to maintain that success. 

"We must prove that Tesla can be sustainably profitable," Musk said on Wednesday's earnings call. "This quarter was big step toward that and I'm incredibly excited about what lies ahead."