The Tesla showroom in Frankfurt, Germany, last year. (Mauritz Antin/EPA-EFE)

Elon Musk’s Tesla posted a lower-than-expected profit for the fourth quarter and a $1 billion loss for all of 2018, the all-electric automaker said Wednesday, renewing questions about how it will fund its grand ambitions as it faces mass layoffs and billion-dollar debts.

Tesla’s $139 million quarterly profit marked the first time the company has recorded back-to-back quarterly profits, and the company’s $21 billion in revenue for the year — up from $11 billion in 2017 — showed it had made considerable progress in its race to dominate the global market for electric cars.

But analysts had expected the company to record about $182 million in profits for the quarter, and the miss appeared to reinvigorate investor concerns over the Silicon Valley automaker’s ability to reach new markets and survive in an increasingly competitive industry. The $50 billion company’s stock fell about 5 percent in after-hours trading.

“Last year was definitely the most challenging year of Tesla’s history, but also the most successful,” Musk told analysts on an earnings call Wednesday.

In April, tweeting a retort to doubts over Tesla’s financial survival — “boring (sigh)” — Musk had assured the world that Tesla would be profitable through the second half of 2018. But in an email to employees earlier this month, Musk had warned that Tesla’s profits would dip in the fourth quarter and that the company would achieve a “tiny profit” at the beginning of 2019 only “with great difficult, effort and some luck.”

That was a sharp turn from the tone Musk set at the end of the third quarter, which he called “historic.” Its higher-than-ever profit in the third quarter, of about $312 million, helped the company calm anxieties over its ability to stay in business. But some market observers, such as RBC Capital Markets analyst Joseph Spak, have estimated that Tesla’s third-quarter results may have marked the company’s “peak profitability.”

Tesla’s cash stockpile in the fourth quarter expanded to about $3.7 billion, critical for covering its expansion and paying off a $920 million debt payment coming due in March. But the company’s challenges remain increasingly urgent. The company has spearheaded two mass layoffs in the last seven months, including cutting 7 percent of its workforce this month. Tesla said the layoffs and “restructuring actions” taken in the quarter will reduce its costs by about $400 million a year.

Tesla broke a record for quarterly revenue, with about $7.2 billion, through the delivery of about 63,000 Model 3 sedans and 27,000 Model S and Model X vehicles. But analysts say it’s unclear whether Tesla will be able to attract enough buyers willing to pay a premium for the company’s quasi-futuristic cars. “Sustainable demand is the real question,” Goldman Sachs analysts wrote in a note to clients this month.

Musk told analysts Wednesday that he expects sales to increase by 50 percent this year, which he called “crazy growth for the automotive industry.” He also dangled the potential for new models, such as a new Tesla pickup truck he said could be unveiled as early as this summer that would be “quite unique, unlike anything else.”

The company said Wednesday that finance chief Deepak Ahuja would retire and be replaced by vice president of finance Zach Kirkhorn, who joined the company in 2010. Ahuja — a company veteran who joined in 2008, retired once before in 2015, and returned shortly after — is one of the highest-ranking executives to leave the company, which has faced a series of executive departures within recent months.

Roughly a decade after it unveiled its first Roadster, Tesla has become one of America’s most valuable automakers, selling three automobiles — the Model S and Model 3 sedans and the Model X SUV — that last year accounted for nearly half of the country’s small-but-growing market for electric vehicles.

Demand for the Model 3 — Tesla’s cheapest car ever sold, at about $45,000, though still pricier than Musk’s years-old $35,000 pledge — has boosted the company’s sales and helped it step ever closer to mass-market affordability. Tesla said it delivered more than 90,000 vehicles in the last quarter of the year, three times as many as it delivered in the same period in 2017.

Musk has told employees that the company, long regarded as a luxury automaker, needs “to reach more customers who can afford our vehicles” if it wants to grow and compete. The company said this month it would institute broad changes in its factory that would reduce the number of top-dollar cars it makes every month.

“While we have made great progress, our products are still too expensive for most people,” Musk wrote. “Tesla has only been producing cars for about a decade and we’re up against massive, entrenched competitors. The net effect is that Tesla must work much harder than other manufacturers to survive while building affordable, sustainable products.”

Tesla said Wednesday it expected to make 7,000 Model 3 sedans a week by the end of 2019 and that it expects to deliver as many as 400,000 cars total this year, up from about 250,000 in 2018.

While Musk has bristled at the idea of raising more money from investors, Wall Street analysts have predicted the company will need to stay afloat and fulfill its expansion plans, including building an assembly plant in China and unveiling new models, such as the proposed Model Y SUV.

“The confluence of economic, competitive, regulatory, political and technological forces may potentially challenge Tesla’s status as a stand-alone entity,” analyst Adam Jonas wrote in a note to clients before the earnings call.

But some analysts have said they remained committed to the Tesla ideal. “Despite these warning signs, we continue to believe the company will be successful … thanks to what could be a ‘business miracle,’ ” wrote Gene Munster and Will Thompson of the venture-capital firm Loup Ventures in a note to clients Tuesday. “Believers in the Tesla story are accustomed to having their faith tested.”