In a year plagued by controversy and conflict, electric carmaker Tesla (TSLA) on Wednesday beat Wall Street earnings expectations, posting a record profit for the third quarter after strong production of its Model 3.

Tesla reported $6.8 billion in revenue against the expected $6.3 billion. The company called the quarter "truly historic," after turning its third-ever profit since going public in June 2009.

"Model 3 was the best-selling car in the U.S. in terms of revenue and the 5th best-selling car in terms of volume," the company stated in a press release.

The Silicon-Valley based company also reported $881 million in free cash flow — shattering an analyst consensus of $191 million. In an April posting on Twitter, CEO Elon Musk claimed Tesla would be profitable and with positive cash flow in the third and fourth quarter of 2018.

Gross automotive margins were above 25 percent, a sharp uptick from 20 percent from the second quarter. 

The company also noted the fourth quarter will be affected China tariffs.

"Gross margin for Model S and X will likely decline slightly in Q4, as we expect that the sequential increase in tariffs in Q4 from Chinese sourced components will be only partially offset by increased manufacturing cost efficiencies," Tesla said. "For all three vehicles, additional tariffs in Q4 on parts sourced from China will impact our gross profit negatively by roughly $50 million."

Shares of Tesla gained 9.72 percent in after-hours trading to $316.53 as of 7:59 p.m. ET.

Tesla had experienced some notable setbacks in 2018. There was a recall of 123,000 Model S sedans over a “corroding bolt” issue in March. In August, Musk posted on Twitter that he was considering taking Tesla private and that funding was secured, leading to an SEC investigation that resulted in $40 million in penalties.

GettyImages-1044441450 The Tesla model 3 is presented on the Tesla stand during the press days of the Paris Motor Show. Photo: ERIC PIERMONT/AFP/Getty Images