Tesla’s surprise profit was its second ever.
Tesla (TSLA) posted a profit of $22 million for the third quarter, which is just the second time it has ever been in the black. Its only other quarterly profit came more than three years ago.
The car company's financial performance beat Wall Street estimates and is much improved from the $230 million loss Tesla reported in the same quarter a year earlier.
Elon Musk, Tesla's CEO, described the profitable quarter as "definitely one of the best moments at Tesla" on a conference call with analysts. Musk also said he thinks Tesla may be profitable again next quarter.
After a difficult first half of the year, Tesla is now shipping a record number of cars per quarter and seeing its profit margins improve on each vehicle.
"I personally probably took a year off my life or more camping out in the freaking factory," Musk said on the call. "We went through bloody hell. We got out of that around mid-June."
Tesla's stock jumped as much as 6% in after-hours trading Wednesday following the results.
In late August, Musk sent an e-mail to Tesla employees imploring them to slash costs and "deliver every car we possibly can" in a mad dash to turn a profit.
"The third quarter will be our last chance to show investors that Tesla can be at least slightly positive cash flow and profitable before the Model 3 reaches full production," Musk wrote in the email.
For Musk, this quarter's results are about more than bragging rights.
Tesla will likely need to raise more money to finance the production of the Model 3, its first mass market car, and build its ginormous Gigafactory. The car company expects to invest billions on each effort.
Musk is also trying to convince shareholders to approve Tesla's acquisition of SolarCity (SCTY), another company with Musk as a chairman and large investor. Like Tesla, it's also a business that typically loses money.
By showing Tesla can be profitable, Musk may be able to make these ambitious efforts easier to swallow on Wall Street.
Tesla previously announced it shipped 24,500 vehicles during the September quarter and remains on track to ship 50,000 cars in the second half of this year. That's roughly as many as Tesla delivered in all of 2015.