The mayor of Pittsburgh is elected to the post in four year terms. The previous mayor, Bob O'Connor, was elected to the position on November 8, 2005 and began to serve January 3, 2006. However, O'Connor was diagnosed with lymphoma of the central nervous system on July 10, 2006. The prognosis was initially good as the mayor began treatment, including chemotherapy, immediately, but O'Connor experienced many complications and died 8:55 PM local time September 1, 2006 at the age of 61. Ravenstahl, president of the city council, was sworn in as the new mayor at 10:36 PM local time, and would serve until a special election would be held to determine if he should complete O'Connor's term.
Primary elections were held for both parties during county-wide elections on May 15, 2007. No candidates ran in the Republican primary, with DeSantis entering the race afterwards. Although it had appeared earlier that councilman Bill Peduto, who ran against O'Connor in the 2005 primary, would challenge Ravenstahl in the Democratic Primary, he dropped out of the race and Ravenstahl won 95.94% of the Democratic primary vote.
Voting by party by neighborhood. The darkest blue shade represents more than 80% of votes were for Ravenstahl. The middle and lightest shades indicate over 65% and 50%, respectively. The darker shade of red represents more than 70% for DeSantis, the lighter shade of red more than 50%.
The general election was held on November 6, 2007 in unusually cold and windy weather which included the city's first snowfall of the year. Voter turnout was estimated to be 28.98%, and very few problems were reported at the polls. DeSantis polled well in more affluent areas of the city, such as Squirrel Hill, while Ravenstahl commanded large portions of the vote in the city's black and working class white neighborhoods, such as the Hill District. The race was more competitive than usual in the heavily Democratic city, but was sufficiently one-sided that the Associated Press declared Ravenstahl to be victorious only slightly more than one and a half hours after the polls had closed and only 20% of city precincts had reported voting totals. DeSantis conceded defeat to Ravenstahl shortly after, around 10 PM local time. Despite losing by more than thirty percentage points in general polling, DeSantis's performance was considered quite good for a Republican candidate, indeed the best performance in several decades.