BEIJING — Tesla is moving closer to becoming the first foreign car company to have a wholly owned manufacturing operation in China — but how much that will really help the company is not yet clear.

For Tesla and other car manufacturers, many of the options in China are guided by the government. One option is to set up a joint venture and share much of its technology — and half the profits — with a Chinese partner. The other is to manufacture in a so-called foreign trade zone in China but still be subject to steep Chinese import tariffs on any cars sold in China.

Carmakers usually end up in a joint venture and have to share their technology. Tesla is taking a different path that reflects the importance the Chinese government is putting on electric cars.

The company has a preliminary deal with the Shanghai municipal government that would give Tesla ownership of its facility, two people familiar with the negotiations said on Sunday.

The operation would be located inside a free-trade zone, said the two people, who insisted on anonymity because they were not authorized to discuss the talks. Being inside a foreign trade zone means that unless Tesla can negotiate a special exemption, the cars could still be subject to China’s steep tariffs — treated as though they were still being shipped from outside China even though they were being produced in the country.

The preliminary deal still offers Tesla control over its trade secrets, however, and may give the company leverage to negotiate better terms with the Chinese government in the future.

Tesla hopes to complete the deal by the end of the year, the two people said.

Any comprehensive arrangement that Tesla and the Shanghai municipal government reach would still require the approval of the central government in Beijing. The Beijing authorities have sometimes used their power to delay deals or demand further concessions from foreign investors.

Persuading Tesla to build cars in Shanghai while still paying tariffs on them would be a coup for the Chinese government, which has tried to turn China into the world’s dominant producer of electric cars. If Tesla were making cars in the Shanghai area, it would have a powerful incentive to buy many, if not most, of the parts in China, strengthening China’s base of suppliers for the fast-growing electric car industry.

China already has the world’s largest market for electric cars, mainly because of extensive subsidies as part of a comprehensive government plan to shift the country away from gasoline-powered cars. The move would not only curbs pollution but also reduce the country’s dependence on imported oil. LMC Automotive, a global consulting firm, estimates that 295,000 cars will be sold this year in China, compared with 287,000 in the rest of the world combined.

That gap may widen. LMC predicts that China’s total will nearly triple in the next two years, while the rest of the world will merely double. That is due, in part, to Chinese government regulations that will require automakers starting in 2019 to sell ever-increasing numbers of electric cars and plug-in hybrids if they want to be allowed to keep selling gasoline cars. China has also begun research on imposing a rule to ban the sale of internal combustion cars someday.

Bill Russo, the founder and chief executive of Automobility, a Shanghai consulting firm, said that Tesla had little commercial choice in starting to build cars in China.

“China is and will be the largest consumer and producer of electric vehicles in the world,” he said. “If Tesla hopes to compete as a global electric vehicle maker, it must tap the manufacturing and supply footprint of China in order to compete globally.”

China has the steepest barriers to automotive trade of any large market in the world, making it extremely difficult to compete in the Chinese market without producing in the country. Beijing has been able to retain steep tariffs and other obstacles to imports because it insisted that it was a developing country when it entered the World Trade Organization in 2001.

The W.T.O. has allowed developing countries to retain much higher trade barriers than industrialized countries, on the theory that they have infant industries that may not have grown big enough to withstand global competition. The anomaly in China’s case, however, is that it now has the world’s largest auto industry by far but it is still heavily protected from international competition.

China charges a tariff of 25 percent on imported cars, compared with 2.5 percent in the United States and 9.8 percent in the European Union. China also has a 17 percent value-added tax — a kind of sales tax — that is charged not only on the price of the car but also on the tariff, so that the taxes are effectively compounded.

Unlike these taxes, the costs of shipping a car across the Pacific are tiny. They can be as little as 1 percent of the cost of a high-priced model like Tesla’s offerings. “Shipping costs are usually not a big deal — it is the 25 percent tariff” that keeps out imports,” said Yale Zhang, the managing director of Automotive Foresight, a Shanghai consulting firm.

Robert Lighthizer, the United States trade representative, has expressed concern about China’s trade practices, and the extent to which they put pressure on global manufacturers to shift production to China. President Trump is due to visit Beijing from Nov. 8 to 10, but China has shown little sign of willingness to negotiate on sectors that it regards as strategic imperatives, and electric cars are one such industry.

China also won an exemption in 2001 from the W.T.O.’s usual rules that bar practically every other country in the world from requiring that automakers set up joint ventures with local partners. So Beijing requires that, except in foreign trade zones, cars can only be made in China for the domestic market through a 50-50 joint venture with a local manufacturer. That requirement has forced multinational companies to transfer a lot of technology and expertise to their Chinese joint venture partners and their suppliers.

If the deal does come to pass, Tesla would have achieved a breakthrough of sorts in being preliminarily allowed to have a wholly owned operation in a foreign trade zone. Honda also received permission to set up an operation in a foreign trade zone more than a decade ago, but unlike Tesla, it has been forced to export the output from that factory, mainly to Europe; that factory was also set up with a complex ownership structure in which a local partner holds a 40 percent stake.

Michael Dunne, a longtime auto consultant specializing in Asia, said that for China to allow Tesla to manufacture in a wholly owned subsidiary in a free-trade zone would be unprecedented. But he cautioned that he did not know what the final arrangement would be on tariffs.

Tesla said in June that it was negotiating to produce cars in Shanghai. But the company has been struggling to decide whether to produce inside or outside a free-trade zone in Shanghai and on what terms.

The Wall Street Journal first reported on Sunday that Tesla had a deal to produce cars in Shanghai, but did not provide details. The Shanghai government had no immediate comment on Sunday night.

Manufacturing cars in Shanghai might help Tesla circumvent a series of policies that various Chinese government agencies have put in place to help domestic automakers at the expense of foreign manufacturers.

Many of the biggest Chinese cities have strict limits on the number of new license plates they issue each year, setting off bidding wars for new plates that can push the plate’s price up to thousands of dollars. But license plates for electric cars are free and readily available.

The catch? The license plates for electric cars are free in most cities only if the car was made in China. The exceptions are Shanghai and Hangzhou, which do not discriminate against imports in their license plate policies, Mr. Zhang said.

“That’s why you see so many Teslas in Shanghai,” he said.

Local governments and the national government also provide thousands of dollars in direct subsidies to electric car buyers. But these subsidies also tend to be restricted to Chinese-made cars. It was not clear if Teslas made in a foreign-trade zone in Shanghai would qualify for subsidies.