Tesla Inc. (TSLA) just surprised Wall Street by reporting a profit for its third quarter.

Diluted earnings per share came in at $1.75 after analysts had predicted a loss of $0.03 per share. Adjusted net income was $516 million. That compared with an adjusted loss of $520 million for the same period last year.

Tesla's revenue for the third quarter came in at $6.8 billion, beating Wall Street's expectations of $6.32 billion. 

The stock was trading up over 13% to $326.20 in after-hours trading (as of 5:10 p.m. ET). Tesla shares sunk by nearly 2% during the regular trading session. 

The solid results were driven partly by strong gross margin expansion as Tesla posted a gross margin of 25.8%, compared to last year's 18.3%. That was due to Tesla's ability to sell Model 3's at higher prices. The earnings release said, "It is clear that 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." Many of the trade-ins were priced at $35,000, the company noted. This could be reflective of what short-seller Andrew Left of Citron Research said Tuesday in a research note about competition. Tesla's cars are clearly killing the competition, Left noted

Cost reductions were also a big part of the picture. "We also delivered on our internal cost-efficiency targets, leading to GAAP Model 3 gross margin of more than 20%, which exceeded our guidance," the company said. 

The profit may potentially alleviate -- or at least subdue -- concerns about Tesla's debt load. Tesla has long been at least partially valued on its ability to raise debt, but that has recently came into question. 

Even though Tesla appears to be beating the competition in electric vehicles for the moment, there may be some long-term risks. A Consumer Reports research note out earlier Wednesday said Tesla cars rank 27th out of 29 car brands in reliability, losing to Asian and European car makers on that front. 

"Even though Tesla is finally hitting its stride in many ways, the company isn't out of the woods yet," said Jeremy Acevedo, industry analysis manager at Edmunds. He added, "tariffs could continue to create complexity in the company's international growth plans, and they will have to create a more sustainable solution to its delivery challenges."