DETROIT (AP) -- General Motors is recalling nearly 780,000 compact cars in North America because the engines can shut down unexpectedly and cause crashes. The company says six people have been killed in crashes related to the problem.

The recall affects Chevrolet Cobalts and Pontiac G5s from the 2005 through 2007 model years.

U.S. safety regulators say the weight of the key ring and rough roads can move the ignition switch out of the run position, cutting the engine and electricity. If that happens, air bags may not work.

GM says there have been 22 crashes from the problem. All were off the road and happened at high speeds.

Dealers will replace the ignition switch for free. GM says owners should remove nonessential items from key rings until the problem is fixed.

The Motley Fool recommends General Motors. Try any of our Foolish newsletter services free for 30 days. We Fools may not all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors. The Motley Fool has a disclosure policy.