D.C. Mayor Vincent Gray outside a polling place in Northeast Washington on Tuesday. He lost the D.C. primary to Muriel E. Bowser, a D.C. Council member. (Jim Bourg/Reuters)

The seeds of D.C. Mayor Vincent C. Gray’s loss on Tuesday were planted during his victory four years ago.

That 2010 race was when businessman Jeffrey Thompson funneled $660,000 in illegal contributions to Gray’s campaign against incumbent Adrian M. Fenty.

The federal investigation into those contributions hung like a dark cloud over Gray’s term — vaguely ominous but, for his first three-plus years in office, largely harmless.

That all changed March 10, when federal prosecutors alleged that the mayor had intimate knowledge of Thompson’s scheme and even conferred with him about it — referring to Thompson by the nom de plume “Uncle Earl.” (Yes, in politics as in the rest of life, truth is stranger than fiction.)

Gray insisted that Thompson had lied to prosecutors about what he knew, although he admitted that he did refer to the businessman as Uncle Earl. The real question is: Why? What had looked like a relatively pedestrian Democratic primary race for Gray became a fight for his political career.

He lost that fight to Muriel Bowser, a city councilwoman whom few people outside Ward 4 — and probably some people inside it — had ever heard of about a month ago. The results made clear that the vote was a rejection of Gray more than an embrace of Bowser. In his home precinct, the incumbent mayor got fewer than half as many votes as he did four years earlier as an insurgent challenger.

Vince Gray, for winning in a way that set up your defeat, you had the worst week in Washington. Congrats, or something.

Have a candidate for the Worst Week in Washington? E-mail Chris Cillizza at chris.cillizza@washpost.com.

Read more from Outlook, friend us on Facebook, and follow us on Twitter.