NEW YORK—Tesla Inc. and its Chief Executive Elon Musk on Thursday accused the U.S. Securities and Exchange Commission (SEC) of harassing them with an “endless” and “unrelenting” investigation to punish Musk for being an outspoken critic of the government. The accusation came in a letter to U.S. District Judge Alison Nathan in Manhattan, who presided over a 2018 SEC settlement stemming from Musk’s tweet about a potential buyout of Tesla. “Mr. Musk and Tesla respectfully seek a course correction,” wrote Alex Spiro, a lawyer for Musk and Tesla. “Enough is enough.” The SEC declined to comment. Thursday’s letter escalates Musk’s battle with regulators as they scrutinize his social media posts and Tesla’s treatment of workers, including accusations of discrimination. It followed Tesla’s disclosure on Feb. 7 that it had received a subpoena from the SEC about its compliance with the 2018 settlement. The SEC sued Musk in August 2018 after …