France's PSA Group has agreed to buy Opel from General Motors in a deal valuing the business at 2.2 billion euros, creating a new European car giant to challenge market leader Volkswagen. (Reuters)

General Motors is selling its two major European brands to French automaker PSA Group and pulling back from the world’s third-largest auto market, where the company has struggled to turn a profit for nearly two decades.

GM’s Opel and Vauxhall brands, as well as the European arm of its financial division, were valued at about $2.3 billion in the transaction. If the deal clears regulators, it is expected to close by the end of the year, the companies said.

PSA Group will then become the second-largest automaker in Europe behind Volkswagen.

The sale includes 11 manufacturing facilities and one engineering center that collectively employ about 40,000 people, according to the companies. GM will incur a noncash accounting charge of $4 billion to $4.5 billion as a result of the sale.

Chief executive Mary Barra told CNBC Monday that the company would not completely exit the European market, and still plans to sell Chevrolet and Cadillac vehicles there.

GM has long lost money on its European brands, despite several turnaround attempts. Barra told an audience in Washington last week that the European operations would have broken even last year if not for the Brexit vote and corresponding economic fallout.

In a statement Monday, Barra said the sale will allow GM to invest in “our core automotive business and in new technologies that are enabling us to lead the future of personal mobility.”

Along with other automakers, GM is pouring considerable sums of money into developing technology for self-driving cars. Last year, the company also invested $500 million in ride-hailing service Lyft and released its first long-range electric vehicle, the Chevy Bolt EV.

The entirety of GM has seen record financial performance in recent years, buoyed in part by strong car sales in the United States. But analysts project little to no growth in the U.S. and European markets in the next several years, prompting leading automakers to turn to Asia.

GM has had a presence in China since 1995 and already sells more cars there than in the United States. The company sold a record 3.9 million cars in China last year, with its Chevrolet, Buick and Cadillac brands proving especially popular. China is the world’s largest car market, followed by the United States.

“The European marketplace, like the U.S. is not expected to grow in the coming years,” Rebecca Lindland, an executive analyst at Kelley Blue Book, said in a statement. “PSA and GM, like everybody else, will look to the enormous potential in both China and India for expansion.”

General Motors has had a presence in Europe since it bought a majority stake in German automaker Opel nearly 90 years ago. General Motors and PSA Group forged an alliance in 2012 to reduce certain production costs, and the companies said last month that they were exploring the possibility of an acquisition.

Read more from The Washington Post’s Innovations section.

The big moral dilemma facing self-driving cars

Why Nissan’s CEO says the human brain still trumps artificial intelligence

Ford to invest $1 billion in artificial intelligence for your car