(Reuters) - Tesla Inc TSLA.O on Wednesday surprised investors with a quarterly profit that sent its shares soaring, as Chief Executive Elon Musk promised a 2020 rollout of a cheaper SUV and more self-driving technology to stay ahead of larger rivals rushing into the premium electric vehicle market he created.

Shares rose nearly 21% to $307.12 after hours on the unexpected news, crossing $300 for the first time since March 1 after record deliveries and cost cuts ensured a profitable third quarter.

Tesla on Wednesday posted a cash balance increase to $5.3 billion and reported a profit of $1.86 per share, shattering analyst expectations for a loss of 42 cents per share.

The third-quarter results are an important milestone for Tesla and redemption for Musk who had to step down as chairman after a series of scandals and investor doubts about Tesla’s ability to withstand competition from larger, better capitalized global rivals.

Tesla’s gross margins, an important profit indicator for investors, surpassed expectations and Tesla said it was “highly confident” in exceeding the low end of its yearly global vehicle delivery goal.

But Tesla has yet to prove that it can be consistently profitable while managing the start of production for Model 3 sedans at its new factory in Shanghai and for Model Y sport utilities next year.

“Given the breakneck speed of expansion, Tesla will face significant demands on its cash pile,” said Nicholas Hyett, an analyst at Hargreaves Lansdown.

The company on Wednesday said production in Shanghai and for Model Y are ahead of schedule, with the latter expected to launch by the summer of 2020.

Tesla also has to contain costs as it develops a gigafactory in Europe, a Semi truck, an electric pickup truck, a new generation of the Tesla Roadster and automated driving features.

Slideshow ( 3 images )

The carmaker said it had cut costs 16% on a yearly basis, citing improvements in operating efficiency and a reduction in manufacturing and material costs. Musk said on a conference call that operating costs were the lowest since Model 3 production started.

Margin expectations are higher for Model Y than Model 3, while productions costs are roughly the same as Model 3, said Zach Kirkhorn, Tesla chief financial officer.

Model 3 vehicles made in the Shanghai factory will have roughly the same margins as those made in Fremont, California, he said.

Tesla also expects to generally be cash flow positive as it has grown to the point of being self-funding. (Graphic: tmsnrt.rs/2MF6HHq)

That will allow the company to invest in divisions focusing on sustainable energy, including launching the third version of its solar roof tile this week.

“For about a year and a half we stripped Tesla energy of resources,” Musk said. “Now that Model 3 production is in a good place and headed to a great place we have restored resources to Tesla storage and solar. That’s going to be really crazy growth.”

Musk also said Tesla is open to supplying batteries and other components to other automakers.

With Wednesday’s after-hours surge, Tesla’s stock has reduced its loss year-to-date to 8% and added about $9 billion to its market capitalization.

Slideshow ( 3 images )

But Tesla rallies have been short-lived before.

A year ago, Tesla gave a quarterly report that similarly smashed investors' expectations, igniting a rally that sent its shares 31% higher over the next two months, only to see the stock decline through much of 2019 over worries about corporate governance, profitability and demand for the Model 3. (Graphic: tmsnrt.rs/2PgxXgT)

Investors in the past have shown impatience with the company’s serial failures to meet financial and production targets. Earlier this month, Tesla shares slumped after the company reported delivering 97,000 vehicles for the third quarter, only 2% ahead of the previous quarter.

But Tesla on Wednesday exceeded promises by billionaire Musk, who in July said Tesla would break even in the third quarter and turn a profit by the end of 2019.

The company has said it plans to deliver 360,000 to 400,000 vehicles for all of 2019, and on Wednesday said it was “highly confident in exceeding 360,000 deliveries this year.”

Analysts have questioned how rapidly Tesla’s vehicle sales will grow as government subsidies for electric vehicle purchases dwindle in the United States, China and other markets.

Kirkhorn on Wednesday said Tesla saw growing order rates in all markets, with current quarter orders exceeding those of the past three months.

Tesla has said it aims to produce at least 1,000 Model 3 cars a week at the new Chinese factory by the end of this year, but it is unclear when it will meet year-end production targets due to uncertainties around orders, labor and suppliers.

Revenue fell nearly 8% to $6.30 billion in the quarter ended Sept. 30. Analysts had expected revenue of $6.33 billion, according to IBES data from Refinitiv.

Tesla on Wednesday said it would gradually release nearly $500 million of accumulated revenue tied to its “full self-driving capabilities”, which customers can buy for $6,000 even though fully automated driving is not available.

Kirkhorn on Wednesday said deferred revenue would also be released as Tesla expands its “Smart Summon” feature, which allows customers to operate a Tesla from 200 feet (60 meters) away using a smartphone app.

Federal safety regulators are looking into the feature after videos began appearing online showing driverless Teslas hitting obstacles or nearly hitting other vehicles.

Musk on Wednesday said software updates over the coming weeks would improve Summon.