Updated 7:20 p.m.| Senator Barack Obama has won North Carolina, according to a New York Times analysis.

Mr. Obama’s slight lead of about .2 percentage points over Senator John McCain has expanded over the last several hours to .4 percent, prompting several news organizations to declare him the winner.

The total shows 49.9 percent for Mr. Obama to 49.5 percent for Mr. McCain.

Mr. Obama’s win here caps an extraordinary campaign in the state, which has not voted for a Democrat for president since 1976.

Early voting gave him a crucial edge when the final tallies were made. In addition, the share of the black vote increased from 2004.

Mr. Obama won early voters by 178,000 votes –and actually lost on Election Day by 165,000 votes, said Tom Jensen, a Democratic pollster based in Raleigh.

“Early voting gave Obama a big advantage,” Mr. Jensen said. “It made it much easier for the campaign to organize rides and get people to the polls over those 17 days of early voting. Obama had a great ground game, but if you only have 13 hours to get everyone out, it’s much harder.”

The weather — rain across most of the state — also played a role, but not in the traditional way. Bad weather usually holds down the Democratic vote because Democrats tend to be poorer and have more difficulty than Republicans getting to the polls. But in this case, it benefited the Democrats because it also held down the Republican vote — and the Democrats had their early votes in the bank.

The state’s 15 electoral votes bring Mr. Obama’s total electoral votes to 364, compared with 162 for Mr. McCain. Twelve electoral votes remain to be counted, 11 from Missouri, which has yet to be called, and one from a Congressional District in Nebraska, which splits its electoral votes.

But the electoral votes are not the story in North Carolina. The story is how the Obama organization turned the tide in this culturally conservative state and then drilled its voters to go to the polls early.

Across the board, Mr. Obama out-performed Senator John Kerry, who lost the state by 12 percentage points to President Bush in 2004. Both blacks and suburban voters came out in record numbers this time. And he cut the Democratic losses in some of the state’s most Republican counties.

Most of Mr. Obama’s margin of victory came in the state’s seven urban centers. This year, 22 percent of the total electorate was black, according to Mr. Jensen’s analysis, compared with 18.6 percent in 2004 (the 2004 figure comes from the state elections board; the exit polls that year were wrong). Mr. Obama won about 35 percent of the white vote. Given the numbers, Mr. Obama’s total was about one-third black and two-thirds white.

In a highly unusual display of monolithic voting, virtually every black woman who voted did so for Mr. Obama, according to the exit polls. Black women made up 14 percent of the vote, the exit polls said, and 100 percent of those surveyed said they voted for Mr. Obama.

Black men made up 9 percent of the vote, and 87 percent of them said they voted for Mr. Obama.

Among whites, Mr. McCain won them overall, but Mr. Obama did much better than Mr. Kerry. Mr. Obama won 37 percent of white voters, compared with 27 percent for Mr. Kerry.

In addition, he improved on Mr. Kerry’s margins among younger voters. Exit polls show that 74 percent of those between 18 and 29 voted for Mr. Obama, while Mr. Kerry drew 56 percent.

Ferrel Guillory, an expert on Southern politics at the University of North Carolina at Chapel Hill, said that the influx of new voters was also an important component of Mr. Obama’s coalition in North Carolina, as it was in Virginia and Florida.

“These states are the most robust in terms of population growth and economic diversification,” he said. The new population gives Democrats a larger pool of “persuadable” voters that Mr. Obama tapped into, he said.

“It’s not that Obama converted the sluggish states in the South,” Mr. Guillory said. “It was the growing states, the more robust states, that gave him the opportunity. It’s important to have a president who understands the unfinished business of the south, but who also sees the opportunity.”