DETROIT — Michigan has cleared the way for Tesla to sell more electric vehicles in the state and get them serviced under a deal filed Wednesday that settles a lawsuit by the automaker.

It won't be as simple as Tesla opening a dealership on a corner lot. But consumers at least won't have to leave Michigan to buy a car or SUV.

Tesla had sued Michigan in 2016, challenging a 2014 law that ensured automakers could only sell through independent, franchised dealers and not directly to customers. The company claimed it was unconstitutional.

The state, under a Republican governor, secretary of state and attorney general, had been defending the law. The deal was reached with Democrats who were elected in 2018.

"Any Michigan resident may lawfully buy a Tesla and have it serviced in Michigan," Attorney General Dana Nessel said.

Teslas will have to be titled in another state and then transferred to Michigan. Repair centers will be allowed as long as they're owned by a Tesla subsidiary.

Thousands of Teslas are on the roads now in Michigan, but they must be sold and serviced across the border in Ohio or another state.

Tesla has what it calls a "gallery" at a shopping mall in Troy in suburban Detroit. Employees there have been barred from talking about pricing or completing sales deals, but those restrictions were lifted under the settlement.

The 2014 law was "drafted by lobbyists for Michigan vehicle dealers and manufacturers whose specific intent was to preclude Tesla from opening company-owned stores in Michigan," Tesla attorney John Bursch said in a 2018 court filing.

There was no immediate comment on the settlement from the Michigan Automobile Dealers Association, which supported the law.