Tesla reported a profit in the third quarter, reversing seven consecutive quarters of losses. It is only the third time in its history that it has achieved this milestone. The third quarter earnings, which were reported after the market closed Wednesday, rocketed shares up nearly 12 percent to above $320.

Tesla reported a profit of $312 million attributed to common shareholders in the three months that ended on September 30, compared with a $619 million loss in the same period last year.

Tesla has had just two profitable quarters in its history, the last of which was reported in 2016. The turnaround at the company was driven by sales of the Model 3, the electric vehicle on which the company and its CEO Elon Musk has placed a considerable bet.

Tesla struck a bullish tone in its letter to shareholders forecasting that the total market potential for Model 3 is larger than just the premium sedan market. The company said customers are trading up their relatively cheaper vehicles to buy a Model 3, even though there is not yet a leasing option and the Q3 starting price of a Model 3 was $49,000.

The company still has yet to introduce a $35,000 Model 3, its initial target price. The cheapest variant of the Model 3 is a mid-range version that has a 260-mile EPA estimated range and a starting price of $46,000. (That price was $45,000 just a week ago and has since been adjusted upwards.) Tesla said it’s “working hard” to bring down the price of Model 3 to $35,000, adding that better than expected Model 3 cost reduction is allowing it to bring more affordable options to the market sooner.

A cheaper Model 3 will maker it harder for Tesla to sustain profits over the long term. That kind of pressure might not unfold in the fourth quarter, but it could eventually come to pass unless Tesla further reduces costs. And even it’s successful, there are bills to pay. Tesla reported $3.5 billion in accounts payable. It has more than $10 billion in debt.

One future bright spot is that the Model 3 is only sold in the U.S. and Canada. Tesla said it will begin taking Model 3 orders for customers Europe and China before the end of the year, allowing the company to tap a larger customer base.

When adjusted for one-time items, Tesla earned $516 million, or $2.90 per share, compared with a loss of $488 million, or $2.92 a share (loss), in the same period last year.

Tesla’s third-quarter earnings showed the company has a free cash flow of about $881 million compared with a negative free cash flow of $1.416 billion in the same period last year. Free cash flow is the amount of cash a company makes after accounting for capital expenditures.

The company total cash increased by $731 million to end the third quarter with $3 billion.

Tesla reported stunning sales of $6.8 billion in the third quarter, more than doubling its revenues of $2.98 billion in the same quarter last year, driven by Model 3 deliveries. Tesla reported sales of $4 billion in the second quarter of this year.

Tesla’s automotive gross margin increased to 25.8 percent under generally accepted accounting principles. The company’s GAAP automotive gross margin was 18.3 percent in the same period last year.

Tesla reported October 2 that it delivered 83,500 electric vehicles in the third quarter, more than double from the previous period as the company steered by Musk pulled out all the stops to get its newest sedan, the Model 3, to customers.

The company said Wednesday it delivered 56,065 Model 3 sedans, up from 18,440 in the previous quarter, which was within its own guidance.