WASHINGTON — A street sign downtown promoting the mayoral candidacy of Muriel Bowser has a single word next to her name: Democrat. Over the four decades that this overwhelmingly left-leaning city has been electing mayors, that has been the only qualification voters have needed to hear.

But the surprising strength of Ms. Bowser’s main opponent, a Republican turned independent, reflects the tectonic shifts in the city’s demographics and economy over the past several years. Combined with a weariness over continuing corruption scandals that have plagued Democrats, the contest seems to herald a new era of competitive races here, regardless of the outcome of this one.

Ms. Bowser’s competitor, David Catania, is trying for a triple: to become the first white mayor since 1872, the first to be openly gay, and the first non-Democrat since 1974, when residents here began voting in public elections after a century of federal control.

In the weeks before Election Day, Mr. Catania has trailed Ms. Bowser in the polls somewhere between 4 and 17 points — numbers that usually spell death in most races for the underdog, but in a city in which Democrats make up 76 percent of 456,633 registered voters, count as remarkably close.