Tesla managed to eke out a small fourth-quarter profit to close 2018, and it pledged to make money in all quarters this year. But staying in the black will be difficult with a major debt payment due and slowing demand for pricier versions of its electric vehicles.

Palo Alto, California-based Tesla posted net income of $139.48 million, or 78 cents per share, from October through December. But its adjusted earnings, which don't include stock-based compensation and other one-time items, fell short of Wall Street expectations. Tesla made $1.93 per share, while analysts polled by FactSet expected $2.20.

On a conference call Wednesday, CEO Elon Musk said the first-quarter profit might be small, but he was optimistic about making money "for all quarters going forward."

The upstart company, which has changed the way people view electric cars worldwide, reported consecutive quarterly net profits for the first time since going public in 2010. Its fourth-quarter revenue more than doubled from a year ago to $7.23 billion, beating estimates of $7.12 billion.

The company's cash position improved by $753 million at the end of the year to $4.28 million, despite repaying $230 million in convertible notes. It had $9.4 billion in debt at the end of the year, a slight improvement over 2017.

For the full year, Tesla lost $976.09 million, or $5.72 per share. Without one-time items, the loss was $1.33 per share, worse than estimates of $1.24.

Shares of Tesla, which rose nearly 4 percent in Wednesday trading, lost the gain after hours when the price fell nearly 5 percent to $294.20.

Tesla wrote in a letter to investors Wednesday that it expects to deliver 360,000 to 400,000 vehicles this year, a growth rate of 45 to 65 percent compared with 2018.

Musk estimated worldwide demand for Tesla's mass-market Model 3 would reach 700,000 to 800,000 per year in a healthy economy, 500,000 if there's a recession. He said there's a significant risk of a downturn within the next 18 months.

The difficulty of making and selling large numbers of cars at a profit is now real for Tesla, which earlier this month cut 7 percent of its workforce in an effort to make the mass-market Model 3 more affordable. In addition, on Jan. 2, Tesla cut prices by $2,000 per vehicle, acknowledging that the pending expiration of a $7,500 federal electric vehicle tax credit will hurt sales. The credit is gradually being phased out for Tesla by the end of the year.

The Model 3 was supposed to start at $35,000, but Tesla has not been able to reach that price and make money. The cheapest version now starts at $44,000. "That's the only way to make affordable cars," he said.

Tesla just began delivering the Model 3 in Europe and China, where Musk said there is strong demand. He said he expects the lower-cost version in the middle of this year.

Some analysts suspect Tesla to swing between profits and losses in the future as it tries to bring Model 3 costs under control.

"Things really aren't going to get any better for Tesla in the U.S. than they did at the end of 2018," Jessica Caldwell, executive director of industry analysis for the Edmunds.com car pricing site, wrote in an email. "Tesla's product lineup is starting to get stale, and now thanks to the elimination of the federal tax credit, buying one has never been more expensive."

Edmunds provides content, including automotive tips and reviews, for distribution by The Associated Press.

In addition to fighting costs, $920 million in Tesla notes come due on March 1. But Tesla said it has "sufficient cash on hand to comfortably settle in cash our convertible bond."

Tesla expects its restructuring to cut costs by $400 million per year, but said its first-quarter earnings would have a one-time restructuring charge of around $40 million. A gap between production and deliveries will create a "temporary but predictable" dip in revenues and earnings for the first quarter, it said.

During the conference call, Musk also announced:

— Chief Financial Officer Deepak Ahuja would retire for a second time in a few months. Musk, who has seen a string of executive departures, announced Ahuja's replacement: Vice President of Finance Zachary Kirkhorn, a nine-year veteran with the company.

— Tesla probably will start leasing Model 3s later this year, although it was reluctant to do so because leasing would hurt the company's bottom line for accounting purposes.

— Tesla probably will have vehicles that drive themselves ready toward the end of the year, but it's up to regulators as to when they're approved.