Returns from 84 percent of the state's precincts showed Corbett with 53 percent of the vote and Onorato with 47 percent.
At Corbett's election-night headquarters at a Pittsburgh hotel, there was wild cheering when a local TV station reported that The Associated Press had declared him the winner. The candidate was expected to address the crowd.
One supporter, Laura Sago, 46, who lives outside Pittsburgh, said she was "thrilled to death" by Corbett's win.
Onorato, the elected executive in charge of Allegheny County government, was with his supporters at a union hall in another part of Pittsburgh.
The gubernatorial campaign, which was occasionally drowned out by the noisier contest for Arlen Specter's U.S. Senate seat, focused primarily on spending and taxes as the state government faces a projected budget shortfall of as much as $5 billion for the fiscal year starting July 1.
But it also revolved around the question of whether the state should tax natural-gas drilling on the lucrative Marcellus Shale reserve; government reform; and the candidates' track records.
Independent polls showed Corbett as the front-runner throughout the post-primary campaign.
Corbett, 61, is a career prosecutor who has been the state attorney general since 2005. He has run largely on his office's ongoing probe of corruption in the Legislature, which has resulted in 10 convictions or guilty pleas and sent a former legislative leader and a former aide to prison. Thirteen other current or former lawmakers and aides are awaiting trial.
Onorato, 49, has run the government in Allegheny County, where Pittsburgh is, as its elected executive since 2004. He touted his success in streamlining the bureaucracy and holding the line on property taxes throughout his tenure.
Gov. Ed Rendell, a Democrat and former Philadelphia mayor, is stepping down in January after serving the maximum two terms allowed by law. Onorato is also from the Pittsburgh area.
Corbett pledged that he would not increase any state taxes or fees, while Onorato promised not to raise the personal-income, sales or gasoline taxes. Both men vowed to cut similar lists of corporate taxes to help enhance the state's business climate, and Corbett has promised to phase out the state inheritance tax.
But during months of campaigning and three televised debates, neither candidate spelled out spending cuts that would come close to closing a $5 billion budget gap.
The issue of taxing natural gas drilling was a defining issue in the campaign.
Onorato advocated a new tax to raise money for environmental protection, including a fund to help local communities repair drilling-related damage to roads, water systems and other infrastructure. He charged that Corbett's opposition stemmed from the more than $355,000 he received in campaign contributions from the industry since the beginning of the year.
Corbett said he opposed the tax because it could be a setback for an industry that's expected to create thousands of new jobs. In TV ads, he accused Onorato of supporting an "energy tax" that would drive up electricity bills.
Between them, the candidates raised more than $40 million for their campaigns and spent much of it on TV attack ads.
Corbett's biggest contributions came from the Republican Party, including $6 million from the Republican Governors Association, and wealthy individuals. Onorato's largest donations came from organized labor, trial lawyers and the party, including $1.4 million from the Democratic Governors Association and more than $300,000 from Rendell's political committee.
Both candidates faced unusual challenges.
Corbett revealed a tendency to make gaffes in public speaking, including his conflicting explanations about which levies his no-tax pledge covered, which became fodder for Onorato's TV ads suggesting that Corbett was not gubernatorial material.
Onorato faced such difficulty in building name recognition that he resorted to airing a TV ad in which he said his last name as he held up a placard on which it was spelled out in capital letters.