The scandal slowed G.M.’s comeback, but it also galvanized its executives to focus on making its cars safer, and ultimately to pursue development of fully autonomous vehicles.

“G.M. is a much more entrepreneurial company now than it’s ever been,” said David E. Cole, chairman emeritus of the Center for Automotive Research in Ann Arbor, Mich. “That has happened since the bankruptcy — the fact they are no longer wedded to doing things the way they did in the past.”

In the summer of 2015, Ms. Barra and other senior G.M. executives began a series of visits to California, to study advances in self-driving cars and to scout potential partners in developing autonomous models.

In addition to observing how companies like Google were developing driverless technology, the executives became acquainted with work being done by Cruise Automation, a tiny start-up working out of a San Francisco warehouse.

By February of last year, officials decided that if G.M. was serious about the race to build the car of the future, it had to move quickly — or risk falling further behind.

“We had to be very honest with ourselves,” Mr. Ammann recalled recently. “There were some capabilities we did not have and that we needed to have if we really wanted to pursue this.”

And it was up to Mr. Ammann — an industry outsider born in New Zealand who worked as a Wall Street investment banker before joining G.M. — to deliver the crucial piece.