The Illinois senator trailed in opinion polls all along but had made up ground in the last few weeks, despite a series of inartful episodes in a campaign that once seemed smooth at every turn.
Clinton was winning 55 percent of the vote to 45 percent for Obama with 99 percent of the vote counted. She won the votes of blue-collar workers, women and white men in an election where the economy was the dominant concern. He was favored by blacks, the affluent and voters who recently switched to the Democratic Party, a group that comprised about one in 10 Pennsylvania voters, according to surveys conducted by The Associated Press and the TV networks.
Clinton won at least 81 delegates to the party's national convention, with seven still to be awarded, according to AP's analysis of election returns. Obama won at least 70. A final count could come Wednesday, or later.
Overall, Obama led with 1,719.5 delegates, including separately chosen party and elected officials known as superdelegates. Clinton had 1,591.5 delegates, according to the AP tally.
Obama also leads in the cumulative popular vote as well as the delegate chase, and there are not many opportunities left for Clinton to turn that around. Moreover, party leaders are growing impatient with the drawn-out struggle and have watched nervously as McCain, his nomination race long settled, has climbed in opinion polls.
Against those forces, Clinton clings to hope that she can persuade party superdelegates to swing behind her en masse.
"We're going to go through the next nine contests and I hope to do well in many of them ... but I'm confident that when delegates -- as well as voters, like the voters of Pennsylvania just did -- ask themselves who's the stronger candidate against John McCain that I will be the nominee of the Democratic party," Clinton told CNN Wednesday.
The keen interest in the primary was reflected at polling stations. Elections officials projected turnout among Pennsylvania's 8.3 million registered voters at 40 percent to 50 percent, double that of the state's primary four years ago.
Some of her aides conceded the Indiana contest in two weeks is another must-win challenge for her.
Obama reported spending more than $11 million on television in Pennsylvania, more than any place else. That compared with less than $5 million by Clinton.
Obama was forced on the defensive by incendiary comments by his former pastor, Rev. Jeremiah Wright, then got into hot water all by himself by saying small-town Americans cling to guns and religion because of their economic hardships.
For her part, Clinton conceded that she had not landed under sniper fire in Bosnia while first lady, even though she said several times that she had. And she replaced her chief strategist, Mark Penn, after he met with officials of the Colombian government seeking passage of a free trade agreement she opposes.
The remaining Democratic contests are primaries in North Carolina, Indiana, Oregon, Kentucky, West Virginia, Montana, South Dakota and Puerto Rico, and caucuses in Guam.