Elon Musk and Tesla have left years of losses in the rear-view mirror.

The electric-car maker announced its first-ever quarterly profit on Wednesday, blowing past analyst estimates.

That's no small feat in the challenging electric-car business. California-based carmaker Coda filed for bankruptcy last week, and fellow Tesla competitor Fisker appears near bankruptcy as well, having laid off most of its employees last month.

The ten-year-old Tesla said last month that it was expecting to finish in the black for the first quarter, but its results still came in better than expected.

The company recorded $562 million in revenue and earnings of $15 million, or 12 cents a share. Analysts surveyed by Thomson Reuters had predicted earnings of four cents a share on $500 million in revenue.

Tesla is still far from convincing all the doubters, however. Nearly half of all available Tesla shares are held by short sellers, making the stock particularly volatile.

Tesla (TSLA) shares surged more than 13% in after-hours trading Wednesday.

Tesla CEO Musk -- reportedly an inspiration for Iron Man hero Tony Stark -- also co-founded online payment system PayPal and heads the commercial space travel firm SpaceX. He maintains a robust presence on social media, with several of his tweets teasing Tesla announcements in the past few months sending its stock upward.

Musk made headlines earlier this year when he responded to a negative review of Tesla's Model S in the New York Times with a detailed blog post challenging the article's veracity, sparking a debate with the paper.

The Model S has received acclaim elsewhere, winning "Car of the Year" honors in 2012 from both Motor Trend and Automobile Magazine.

Tesla initially expected to sell 4,500 Model S's in the first quarter, with prices starting between $70,000 and $100,000 depending on the features customers choose. Instead, it sold roughly 4,900.

Tesla's earnings were also boosted by its sales of zero-emission-vehicle credits to other automakers, which generated $68 million in revenue for the quarter.

The credit system was set up by the California state government to push automakers to produce environmentally friendly vehicles. Manufacturers of gasoline-powered vehicles can purchase the credits accrued by green-car producers like Tesla.

Tesla said in a letter to investors that it was seeing "strong global demand" for the Model S, and is currently receiving orders "at a rate greater than 20,000 per year worldwide."

The company recently announced a new financing program for Model S buyers backed personally by Musk, whose net worth Forbes Magazine pegged at $2.7 billion as of March. He has already invested over $100 million of his own money in the company.