Jim Kenney started 2015 eager to run for mayor but uneasy about leaving the at-large City Council seat he had held for six terms.
Then the city's political landscape shifted swiftly and sharply in his favor.
Kenney, who handily won the Democratic primary election Tuesday night, became a candidate at the end of January, due largely to factors over which he had no control.
First, City Council President Darrell L. Clarke - the first choice for most of the city's unions - ruled out a run Jan. 12.
Then, former City Solicitor Ken Trujillo, who spent two years planning his campaign, dropped out of the race Jan. 21.
A few days later Kenney declared. With that, Trujillo's staff became Kenney's campaign infrastructure, and labor support that had been in Clarke's corner migrated to Kenney as well.
He was off and running, offering something for everyone, according to Randall Miller, a history professor at St. Joseph's University who studies local politics. He could tout his union ties to the lunch-pail crowd and his legislation decriminalizing marijuana possession to younger voters.
"He was the perfect candidate because he could be both old and new at the same time," Miller said.
As the landscape tilted to Kenney's advantage, State Sen. Anthony Hardy Williams started to lose his footing in the race.
Williams, now in his fifth Senate term, declared his candidacy for mayor six months ago but appeared to be planning his campaign not long after he finished third in the 2010 primary for governor.
Williams was at ease in the early days of his campaign and was expected to contend for front-runner.
But the Williams campaign floundered and flailed to its end, undone by an inability to counter Kenney and fatally flawed assumptions about racial math. Kenney is white. Williams is African American.
Late in the primary, Williams supporters pitched it as a referendum on civil rights, asking black voters if they wanted to relinquish their hard-won political power in the city. Voters didn't buy it.
This was a reversal of political fortunes.
Williams, who easily won seats in the state House in 1988 and Senate in 1998, has rarely faced a competitive race. His campaign was run by a small cadre of longtime allies accustomed to easy victories.
Kenney came perilously close to losing his Council seat in the 2011 election. His campaign this year was run by young pros who managed to keep a lid on the candidate's occasionally irascible outbursts.
Money and race were expected to factor mightily in the primary. Both fell well short.
Mayor Nutter, who is black, won his office in 2007 with strong support from white voters.
"A black candidate can get white votes and a white candidate can get black votes," Nutter said. "But the bottom, bottom line, as we all know in politics, is that you have to go after them."
Miller said Williams mistakenly "assumed, since he's a prominent African American, he would get the black vote by default."
Kenney racked up key endorsements from high-profile black politicians - Clarke, Councilwoman Marian B. Tasco, State Rep. Dwight M. Evans. That unsettled the Williams camp.
Williams was supported by the three founders of Susquehanna International Group, a Main Line stock trading firm. That trio used an independent political action committee, American Cities, to pour nearly $7 million into pro-Williams commercials.
That was a 2-1 advantage over two independent PACs airing pro-Kenney commercials.
American Cities focused on a single issue - improving access to quality education. The PAC was unwilling to run ads attacking Kenney.
Political consultant Ken Smukler said such ads "would have pushed Tony" to a primary victory by cutting into Kenney's momentum. Instead, Williams was left to attack Kenney on his own.
"When the campaign realized the Susquehanna guys cared more about their reputations in the political marketplace than Tony Williams winning, then they were forced to go negative," he said.
Williams went after Kenney for comments he made in 1997, complaining about restraints on the use of force by police officers.
Then came what former Gov. Ed Rendell called a "colossal mistake."
During the final televised debate, Williams declared that he would dismiss Police Commissioner Charles H. Ramsey - one of the most popular public servants in the city - for overseeing his department's controversial stop-and-frisk strategy.
"That was probably as bad a mistake in an election as I've ever seen," Rendell said. "It was nuts."
Nutter, who responded by suggesting that Williams might not be smart enough to be mayor, said he was stunned.
"For me, that came out of nowhere," Nutter said.
Neil Oxman, a political consultant who produced television ads for a pro-Kenney political action committee, called the Ramsey attack "the dumbest thing in the world."
"When you get behind, you do desperate things," Oxman said.
Williams, already wobbly, never recovered in the campaign's closing weeks.