Tesla (TSLA) posted a profit in the second quarter, defying Wall Street estimates after the electric car-maker delivered more vehicles than expected in the quarter despite virus-related disruptions.

Here were the main results from Tesla’s Q2 report, compared to consensus estimates compiled by Bloomberg:

  • Revenue: $6.04 billion vs. $5.4 billion expected vs. $6.35 billion Y/Y

  • GAAP earnings per share: 50 cents, vs. GAAP loss per share of $1.06 expected and GAAP loss per share of $2.31 Y/Y

  • Free cash flow: $418 million, vs. outflow $617.9 million expected

Tesla’s second-quarter results came on the heels of an incredible 280% stock rally for the year to date as investors bet on the company’s long-term prospects, with the coronavirus pandemic weighing more heavily on established auto competitors. The near-fourfold increase in Tesla’s stock made it the second-best performer in the Nasdaq 100 after Moderna (MRNA), and rocketed Tesla’s market capitalization to nearly $300 billion to make it the world’s most valuable automaker. Shares of Tesla rose more than 2% in late trading, as of 4:28 p.m. ET.

Heading into the report, investors honed in especially on Tesla’s bottom line to see whether the company would eke out a profit based on GAAP (Generally Accepted Accounting Principles). The company pulled off a fourth consecutive quarter of GAAP profitability, making the stock eligible to be considered for inclusion in to the S&P 500 – a milestone which would broaden the pool of potential investors into Tesla’s stock.

“Our operating profit improved in Q2 despite challenging circumstances,” Tesla wrote in its earnings release. “Positive impacts included lower operating costs due to a temporary reduction in employee compensation expense, a sequential increase in regulatory credit revenue and deferred revenue recognition of $48M related to a Full Self Driving (FSD) feature release.”

“These positive contributions were offset by significant costs related to factory shutdowns, as well as a sequential increase in non-cash SBC [stock-based compensation] expense primarily attributable to $101M to 2018 CEO award milestones,” Tesla added.

A Tesla Model 3 car is displayed during the Tesla China-made Model 3 Delivery Ceremony in Shanghai. (Photo by STR/AFP via Getty Images)

Heading into the report, consensus estimates suggested Tesla would report a modest GAAP loss for the second quarter. However, many investors and individual analysts expected the company would post a profit after Tesla reported better than expected deliveries earlier this month.

Tesla said in early July that it delivered 90,650 vehicles in the three months ending in June, after delivering about 88,400 in the first quarter of the year. The sequential increase came even as Tesla grappled with a nearly twomonth closure of its factory in Fremont, California – the company’s only car-making facility in the US. The factory, closed in March as virus-related shutdowns swept California, came back online in mid-May.

Despite the temporary pause in US production, Tesla doubled down on its goal of delivering at least 500,000 vehicles this year. Tesla first introduced that target in January this year, saying at the time before the global pandemic that it expected deliveries “should comfortably exceed 500,000 units.”

“We have the capacity installed to exceed 500,000 vehicle deliveries this year, despite recent production interruptions,” Tesla said in its Wednesday update. “While achieving this goal has become more difficult, delivering half a million vehicles in 2020 remains our target.”

Tesla’s newly ramped facility in Shanghai offered some respite as the pandemic overtook the US during the second quarter. While Tesla did not break out Q2 production or delivery figures by geography, the company. said the Model 3 has “received a strong reception in China.”

Tesla added that construction for Model Y lines at the Shanghai factory is “progressing as planned,” and first deliveries are expected in 2021.

This post is breaking. Check back for updates.

Emily McCormick is a reporter for Yahoo Finance. Follow her on Twitter: @emily_mcck

Read more from Emily:

Find live stock market quotes and the latest business and finance news

For tutorials and information on investing and trading stocks, check out Cashay

Follow Yahoo Finance on TwitterFacebookInstagramFlipboardLinkedIn, and reddit.