California’s closest race for state attorney general in decades drew to a close Wednesday, more than three weeks after Election Day, as Republican Steve Cooley conceded to Democrat Kamala Harris, completing a Democratic sweep of statewide offices.

Cooley, the Los Angeles District Attorney, issued a statement saying that although the margin remains narrow and some ballots are still being counted, his campaign believes he can’t make up the gap. He congratulated Harris, the San Francisco District Attorney, on her win, but not without a bit of a dig.

“It is unfortunate that someone who is a nonpartisan non-politician could not overcome the increasingly partisan tendencies of the state, even for an office that by its nature necessitates a nonpartisan approach,” Cooley said.

“I take great pride in the fact that I received the endorsement of every law enforcement organization in this race as well as that of every major daily newspaper in California but one. I was particularly gratified to receive the support of so many fellow district attorneys. While my campaign team tells me that endorsements do not necessarily win elections — and the results confirm that — it still means a great deal to me on a personal level.”

Cooley, 63, had declared victory late on Election Day, but by the next morning the numbers were showing that had been premature. The postelection maneuvering as ballots were tallied became almost as acrimonious as the campaign itself, with each camp accusing the other of trying to manipulate how ballots were counted.

Harris, 46, will be the first woman and the first person of color to serve as California’s attorney general. After serving as a prosecutor in Alameda County and San Francisco and as a San Francisco deputy city attorney, she defeated two-term incumbent District Attorney Terence Hallinan in 2003. She has continued building her political networks since, notably with her work on Barack Obama’s 2008 presidential campaign.

Harris campaign manager Brian Brokaw issued a statement Wednesday saying Harris thanked Cooley for “a spirited campaign” and looks forward to working with him on the state’s public-safety challenges.

“The counties continue to tabulate votes, and District Attorney Harris believes it is only appropriate to wait until all the votes are counted before making a public declaration,” Brokaw said. “She will be holding a news conference on Tuesday, the deadline for counties to report final counts to the Secretary of State.”

As of Tuesday night, Cooley had 4,324,924 votes, or 45.5 percent of those cast, while Harris had 4,376,509 votes, or 46 percent, according to the Secretary of State’s office.

Cooley actually outperformed Republican gubernatorial nominee Meg Whitman, who spent a record $144.2 million of her own money to get 4,084,436 votes.

“Every single Republican candidate for statewide office except Cooley lost by double digits,” Cooley campaign consultant Kevin Spillane noted Wednesday.

“We maximized the votes we could get outside of Los Angeles. I never thought we were going to carry Los Angeles County; the question was what the margin of loss would be,” he added. But in the end, “a huge democratic surge in turnout” made that margin too large to overcome.

Read the Political Blotter at IBAbuzz.com/politics. Follow Josh Richman at Twitter.com/josh_richman.