Maryland gubernatorial candidate Attorney General Douglas Gansler speaks to supporters at an election night party in North Bethesda on Tuesday. (Jose Luis Magana/AP)

Douglas F. Gansler was the envy of Maryland’s political world in early 2013, as he openly mulled a campaign for governor.

Already undefeated in two statewide races, Gansler had a robust record of accomplishment and $5.2 million in his campaign account — more than three times what had been amassed by Lt. Gov. Anthony G. Brown, his chief rival in the race to succeed Gov. Martin O’Malley (D).

To many Democratic strategists, Gansler was the undisputed front-runner, a stature that made his humiliating defeat in Tuesday’s Democratic primary all the more remarkable.

After 16 years as one of Maryland’s most prominent leaders, a man whose political ambition once seemed as vast as his potential, Gansler saw his career stall at the moment he expected to celebrate a crowning achievement.

His collapse resulted from an array of factors, say allies and political strategists, beginning with the timing of his announcement, which occurred months after Brown’s. In the interim, Brown chose as his running mate Ken Ulman, the Howard County executive whose $2 million war chest helped neutralize Gansler’s fundraising edge.

“Eighteen months ago, Doug was the candidate to beat,” said Mike Morrill, a Democratic strategist and a former Gansler campaign adviser. “By the time Doug came to what he thought was the starting line, the race was already underway, and he was behind.”

On election night, the numbers told a story of political devastation. From Baltimore to Garrett County, Brown built a lead of nearly 30 percentage points over Gansler, who strained in some areas to keep up with Del. Heather R. Mizeur (Montgomery), once regarded as the race’s long shot.

Even in Montgomery County, where Gansler lives and launched his political career, Brown swamped him by nearly 15,000 votes.

“We fell short today, not because of a lack of hard work or conviction or dedication,” Gansler told supporters Tuesday night, his voice a mix of defiance and resignation. “We worked hard. You all worked hard. But tomorrow we wake up, we shake off the dust, and we each do what we can to help others build a better life here in Maryland.”

For months, his loyalists were baffled by his struggle to mount a more competitive campaign. After all, he had risen from state’s attorney in Montgomery County to attorney general with relative ease.

If his adversaries and even allies sometimes lampooned his inartful candor, if they derided him as a grandstanding, lacrosse-loving frat boy, they also predicted that he could be a formidable contender for governor.

“I believed Doug was a master strategist,” said Del. Kathleen M. Dumais (D-Montgomery), a supporter. “And I was pretty sure he would have the political campaign to get it done.”

Gansler was never assured of an easy path to victory. Brown had the support of O’Malley and the Democratic establishment, and the historic distinction of potentially becoming the state’s first black governor.

Yet no Maryland lieutenant governor had ever won the premier job, and Brown was largely unknown to voters. His main responsibility as O’Malley’s deputy — overseeing the implementation of the Affordable Health Care Act — was considered a fiasco.

Gansler forfeited whatever advantages he had soon after announcing his candidacy, when he was stung by revelations that he ordered state troopers to violate traffic laws and that he hadn’t stopped apparent underage drinking at a party his son attended.

The stories allowed Brown to portray Gansler as reckless and undisciplined, chatter that dominated the race as voters began paying attention.

“If you don’t make your campaign about big things, the media and your opponent will make it about little things real fast,” said state Sen. Jamie B. Raskin (D-Montgomery), a longtime friend. “His campaign got buried in petty distractions right from the beginning.”

Gansler was further weakened, strategists said, by not investing enough in ground-level campaign operations in key counties such as Montgomery and Prince George’s.

Eugene Grant, Seat Pleasant’s mayor and a Gansler supporter, said he urged the campaign to hire workers to knock on doors. Instead, he said, Gansler relied on volunteers, who “can’t be out there seven days a week.”

Gansler’s biggest failure, perhaps, was not finding a transcendent issue to electrify voters. His message often was muddled. He pleased progressives by trumpeting the environment and then made a show of advocating a pro-business cut in the corporate income tax.

By spring, as polls showed him trailing by more than 20 points, Gansler resorted to attacking Brown, at times so aggressively that he upset his own supporters.

“Most observers found the distinguishing, core rationale for the Gansler candidacy to be in­cred­ibly unclear and unsettled,” said Keith Haller, a Maryland pollster. “If the political junkies couldn’t figure it out, you can imagine how murky it must have been for average Democrats.”

As he greeted prospective voters in Bethesda on Monday, Gansler told reporters that his campaign had “done a great job” and said he was “confident we’re going to win.” He declined an opportunity to assess his own missteps. Instead, he talked about his campaign facing an “uphill climb,” because Brown took contributions from special interests.

None of that concerned Sabina Radin, 56, a special education teacher, as she approached him.

“I’m going to bring up something — the party,” she said, a reference to the Beach Week incident, requiring Gansler to patiently explain himself yet again.

Hours later, as Brown and Mizeur hosted rallies, Gansler retreated to a place he has always loved: a lacrosse field. At one point, he had the ball and was zig-zagging through a thicket of defenders, looking for his moment to score.

“Give it up, Dougie! Give it up!” his coach yelled. But Gansler kept the ball, still running, still searching for his opening.

Jenna Johnson contributed to this report.