G.M.’s shares gained $1.19 to close at $34.19, up 3.6 percent from their initial public offering price of $33. Earlier, the shares had risen as high as $35.99. Trading volume was heavy, with more than 450 million shares exchanging hands.

The offering, which raised $23.1 billion, is bigger and more ambitious than had once seemed possible. But the recently bankrupt automaker will have to build on its revival for the government to recoup its entire $50 billion investment and validate the Obama administration’s decision to keep G.M. from collapsing.

To break even, the Treasury Department will need to sell its remaining 500 million shares at an average price of $53 each in the months and years to come. And while the administration may retain great influence over the company, it may not be able to keep stoking the enthusiasm investors have shown for G.M. stock in recent days.

Still, now that General Motors has shown that it can be profitable, a complete exit by the government could happen even within the next two years. With the offering, G.M. is shedding its ties to the government faster than expected, cutting the Treasury Department’s ownership stake to 26 percent, from nearly 61 percent.

The offering, President Obama said on Wednesday, continues “our disciplined commitment to exit this investment while protecting the American taxpayer.”

The administration had argued that saving G.M. was not just about one company, but about an entire web of businesses connected to its fortunes. On Wednesday, the nonprofit Center for Automotive Research released a study saying that government aid to G.M. and Chrysler saved more than 1.1 million jobs in 2009 and 314,000 jobs this year — the highest figure yet reported.

Indeed, 17 months after G.M. entered bankruptcy protection, there has been a broader revival in the American car industry. People involved in the offering process, which was intended to be private, credited recent gains in Ford Motor’s share price as a boon to their own efforts. Largely seen as bloated and incapable of competing with nimbler foreign competitors as recently as last year, automakers like G.M. and Ford have turned around their operations by wringing greater efficiency and lower costs out of their work forces and operations.

Investor demand during the company’s two-week global roadshow to promote the offering had proved so strong that administration officials and another major stakeholder, the United Automobile Workers union, elected to sell significantly more shares than planned. G.M. has raised $18.1 billion from selling common shares and $5 billion from preferred shares.

The stock sale follows months of sometimes tough discussions between the company and the Treasury Department, led by officials like the former investment banker Ron Bloom, over how much stock to sell and at what price. For G.M., it has long been an important goal to rid itself of the “Government Motors” moniker it insists is hurting car sales.

For the government, more complicated demands are in play. Its bailout of the automaker was premised not on making money, but on preserving jobs. Still, it is under pressure to minimize losses — or even to eke out a profit — by selling its shares at high enough prices. The government has already recovered more than $7.4 billion from G.M., including interest and dividends.

Senior administration officials said on Wednesday evening that they had worked closely with G.M. and its underwriters in settling on the $33 price. The Treasury Department must now wait six months before it can sell more shares. People with direct knowledge of the matter, who were not authorized to discuss it, estimated that the government would make another significant sale of its holdings next year.

There are reasons for both company and government officials to be confident. G.M., freed from much of its debt and overhead costs, became profitable this year and has earned $4.2 billion through the first three quarters. And although it jettisoned four of its eight brands in bankruptcy, the company managed to stabilize its United States market share at 19 percent and continue to invest in new vehicles.

“Many of the critics believed it would never come out at all or it would come out wounded,” one senior administration official said on a conference call on Wednesday evening.

Last summer, Edward E. Whitacre Jr., General Motors chief executive, said that he would prefer that the government sell off its stake in one shot. But the sheer size of the Treasury’s holdings made that impossible, according to the people involved in the process. Still, the administration’s viewpoint on how much to sell evolved, as it began to see an opportunity to exit its G.M. investment quickly while maximizing the profits from its stock sales.

“The government began thinking more like a private equity firm,” said one banker involved in the process. (The current chief executive of G.M., Daniel F. Akerson, is a former executive of the private equity firm the Carlyle Group.)

When the new G.M. begins trading on Thursday — under its old “GM” ticker on the New York Stock Exchange and “GMM” on the Toronto Stock Exchange — its shares will initially be held by a wide array of investors, from big mutual funds to hedge funds to sovereign wealth funds in the Middle East and Asia. (Shares of the old G.M. — the bad assets that were split off in bankruptcy as the Motors Liquidation Company — still trade for pennies, essentially worthless.)

G.M. has also agreed to sell a 1 percent stake to SAIC Motor, a major partner of the company in China, according to some of the people with direct knowledge of the matter.

Fulfilling an implicit mandate from Treasury, the largest allocation of G.M. shares has been made to institutions representing American retail investors, these people said. The move was meant in part to blunt criticism that taxpayers would be cut off from what company and government officials insist was a potentially big rise in G.M. shares. (Several of the people involved in the offering said they expect to see a potential 10 to 20 percent jump in the share price on Thursday, typical for an initial offering.)

Led by G.M.’s relatively new management team — Mr. Akerson has been chief executive for only three months — the company embarked on a two-week dash around the world to drum up interest in the company. Initially priced at $26 to $29 a share, G.M. stock got a rosier forecast as underwriters were overwhelmed with order requests, prompting the decision on Monday to raise the target to $32 to $33 a share, these people said.

The offering’s unexpectedly high price may bolster the public standing of the underwriting banks, which have at times been at odds with the government in other matters. The underwriters, a huge group led by Morgan Stanley and JPMorgan Chase, with Bank of America and Citigroup also playing major roles, will not receive a big payday from the offering. The lead underwriters are set to receive roughly a fee of 0.75 percent, low by bankers’ standards, according to people with knowledge of the matter.