WASHINGTON — For 36 years, elections for governor of Virginia have unfailingly followed this pattern: whichever political party holds the White House loses.

But despite President Obama’s tepid job approval ratings, Democrats have a shot at breaking that rule this November. Some polls show the Democratic nominee, Terry McAuliffe, with a narrow lead over Kenneth T. Cuccinelli II, his Republican challenger.

“Why is McAuliffe ahead?” asked Tom Davis, a former Virginia congressman and Republican strategist.

One important reason: The same demographic shifts that made it possible for Mr. Obama to carry Virginia twice after 10 consecutive Democratic losses have raised the water level for the party’s statewide candidates, too.

The swelling number of Virginia’s suburban, college-educated, moderate, minority voters — black, Hispanic and Asian — is hardly the only factor shaping the race. It is certainly not the most conspicuous, as scandal swirls around Gov. Bob McDonnell, the departing Republican, and buffets Mr. Cuccinelli at the same time.