The close contest between Mr. Clarke, a strong gun-rights supporter, and a Democratic rival backed by Mr. Bloomberg was the latest high-profile test of the billionaire independent’s sway over local gun-control politics.

Mr. Bloomberg has spent millions of his fortune trying to elect local candidates that share his embrace of more gun control and lobbying statehouses to pass stricter firearm laws.

Tuesday’s outcome — which follows several other tough defeats for Mr. Bloomberg since 2013 — underscores the limits of his influence.

As WSJ’s Reid Epstein reported earlier, Mr. Bloomberg’s Independence USA super PAC spent more than $150,000 on TV ads criticizing Mr. Clarke for his position on guns. The conservative Democrat has urged citizens to protect themselves with firearms instead of just relying on a spread-thin police department for their safety.

The Milwaukee County primary marked the first time this year that Mr. Bloomberg purchased air time to steer a local race.

The election follows the former mayor’s defeat in last year’s historic recall vote in Colorado that ousted two state senators who had voted for stricter gun-control measures. The mayor gave $350,000 to a Colorado committee formed to defeat the recall.

In the last year, Mr. Bloomberg has also struggled to persuade state lawmakers in Oregon, Washington State and Nevada to pass laws expanding background checks on gun purchases.

But not all of Mr. Bloomberg’s efforts to counter the National Rifle Association’s influence have fallen short.

He threw more than $1.5 million behind Virginia Democrat Terry McAuliffe’s successful campaign for governor. And last year, he helped pro-gun candidate Robin Kelly capture an Illinois congressional seat. And in 2012, he contributed to the defeat of an NRA-backed California congressman, Joe Baca.

But the ex-mayor has made more headway in the corporate world, where he’s pushed companies like Target, Chipotle and Starbucks to take stands against customers bringing guns into their stores.

A spokesman for Mr. Bloomberg declined to comment on Mr. Clarke’s win.

“In the end, Bloomberg’s money could not buy the hearts and minds of the voters,” said NRA lobbyist Chris Cox in a statement.

About Washington Wire

Washington Wire is one of the oldest standing features in American journalism. Since the Wire launched on Sept. 20, 1940, the Journal has offered readers an informal look at the capital. Now online, the Wire provides a succession of glimpses at what’s happening behind hot stories and warnings of what to watch for in the days ahead. The Wire is led by Reid J. Epstein, with contributions from the rest of the bureau. Washington Wire now also includes Think Tank, our home for outside analysis from policy and political thinkers.