Tesla finally hit Elon Musk's production goal for the Model 3.

The company said in a regulatory filing Monday that it produced 5,031 Model 3s in the last week of the second quarter.

Tesla also raised its production target for the Model 3, its most accessibly priced electric car. The company said it expects to make 6,000 per week by late next month.

The Model 3 had missed two ambitious production targets, but Musk had promised investors that the company would make 5,000 Model 3s per week by about this time of year.

"The last 12 months were some of the most difficult in Tesla's history, and we are incredibly proud of the whole Tesla team," the company said in the filing. "It was not easy, but it was definitely worth it."

Tesla said later in the day that its top engineer, Doug Field, was leaving the company after almost five years. Field took a leave of absence earlier this year. Musk has called him "one of the world's most talented engineering execs."

A Tesla spokesperson said the company thanked Field "for his hard work over the years and for everything he has done for Tesla." The spokesperson did not say why he's leaving.

The filing comes after Musk tweeted late Sunday that Tesla's team produced 7,000 cars in seven days. Tesla produced 1,913 Model S and Model X vehicles, it said in the filing.

Musk wrote to Tesla staffers that Tesla had achieved its goals. "I think we just became a real car company...." he reportedly said in the memo. Tesla did not respond to a request for comment about the memo.

7000 cars, 7 days

♥️ Tesla Team ♥️ — Elon Musk (@elonmusk) July 1, 2018

Musk's promise was a major test for the company, and investors were anxiously watching the production outcome.

Tesla stock opened sharply higher, but it drifted lower throughout the day and closed down 2.3%.

One analyst, Efraim Levy of CFRA Research, wrote to clients that he does not believe the rate of 5,000 Model 3s per week is "operationally or financially sustainable." He said he does expect it to become sustainable over time.

Related: Elon Musk vs. the world

Tesla confirmed it expects to turn a profit in the third and fourth quarters. It has only reported two profitable quarters in eight years as a public company and is deep in debt. The company is facing questions about its balance sheet, and Musk has lashed out against critics in recent months.

Musk continued to insist that he would hit the target of 5,000 Model 3s a week, and that it would give the company enough sales and profit to make it unnecessary to raise more cash.

Clarification: This story has been updated to note the Model 3 is Tesla's most accessibly priced car.