But it seems to have shaken off many of its troubles by cutting costs, lifting deliveries to record levels and dipping into a pool of money it had been required to set aside.
The electric-car maker’s suddenly robust position was detailed Wednesday when it reported $143 million in net income in the third quarter, defying analysts’ expectations of a loss.
Tesla said it had earnings of $1.86 per share on an adjusted basis. Revenue was $6.3 billion in the quarter.
Analysts had expected a loss of 46 cents per share and revenue of $6.4 billion, according to FactSet.
“Investors will love the results,” said Erik Gordon, a business professor at the University of Michigan who follows the auto industry.
And they did. The news sent Tesla’s shares up about 20 percent after the close of regular trading.
In the first two quarters of the year, Tesla lost a total of $1.1 billion. The company said Wednesday that it had been able to surge to a profit because it had removed “substantial cost” from its operations — so much that profit rose even though revenue fell slightly.
“Execution was outstanding on just about every front,” Tesla’s chief executive, Elon Musk, said in a conference call.
Mr. Musk offered an upbeat outlook. By the end of the year, he said, Tesla should begin production at a factory in Shanghai and announce the location of a plant to be built in Europe.
The company plans to begin producing its next vehicle, the Model Y, next summer, about six months sooner than previously expected.
Mr. Musk predicted that the Model Y would surpass the combined sales of Tesla’s current vehicles — the Models 3, S and X — and generate better margins than the Model 3.
He also said that by the end of next year, Tesla should be able to activate self-driving technology “reliable enough that you do not need to pay attention, in our opinion.” He cautioned that regulators might not concur about the technology’s readiness for autonomous driving.
Tesla said capital expenditures totaled $385 million in the quarter. That was more than the $250 million spent in the second quarter, but down from $510 million in the third quarter a year ago.
At the same time, it said, its cash on hand grew to $5.3 billion, an increase of $383 million. Tesla reported $371 million in free cash flow, a measure of cash generated beyond operating expenses and capital spending.
“The profit and cash-flow numbers look unexpectedly good,” Mr. Gordon said. “The cash flow is especially important because there were concerns about the company’s financial position.”
Tesla also benefited by recognizing deferred revenue — money that had been set aside because it came from customer payments for features not yet activated, such as aspects of the Autopilot system. Autopilot uses radar and cameras to drive Tesla cars with little input from drivers. In September, Tesla activated the Smart Summon feature, allowing the company to recognize some deferred revenue in the third quarter.
Smart Summon is supposed to enable a vehicle to navigate from a spot in a parking lot to a waiting driver, although some online videos have shown crashes or near accidents while the feature was in use.
Tesla reported this month that it delivered 97,000 cars in the third quarter, up from 95,000 in the second quarter. But the sales gain reflected demand for its least expensive offering, the Model 3.
The most affordable version of the Model 3 sells for $39,500. The Model S luxury sedan and Model X sport utility vehicle sell for $80,000 and up, but their sales have fallen as Model 3 production has increased. In the third quarter, Model S and X sales totaled 17,400 vehicles, compared with Model 3 sales of 79,600.
Before the earnings report on Wednesday, Tesla’s stock closed at $255, down about 18 percent since the beginning of the year. Tesla still had a market value of $46 billion, about $10 billion more than Ford Motor.
Tesla has forecast it will sell 360,000 to 400,000 cars this year, and to reach the bottom of that range it will need fourth-quarter sales of 105,000 vehicles.
Automakers typically see strong sales in the year’s final three months, and Tesla could benefit if consumers in the United States rush to take advantage of the $1,875 federal tax credit available to buyers of Tesla vehicles. The tax credit will cease at the end of the year.