He had been frail for years, suffering at various points from diabetes, recurring infections and a bad kidney. As recently as February, after another extended hospital stay, friends and colleagues had braced themselves for the possibility of Marion Barry’s death.

Yet, for all his months of deepening decline, the announcement that Barry had died early Sunday stunned a city where for four decades he had reigned as its invincible and rollicking political star.

A presiding D.C. Council member and former four-term mayor, Barry was that rare elected leader who personified his city, as Richard J. Daley was Chicago in the 1960s and Edward I. Koch was New York City’s signature voice during the 1980s.

(Timeline: The life of Marion Barry)

Barry’s many triumphs inspired civic and racial pride in “Chocolate City,” as the District was known when its population was majority African American and where he celebrated the empowerment of black Washingtonians.

Yet Barry also was the source of national and even international embarrassment, the defining moment being when federal agents videotaped him smoking crack cocaine at a downtown Washington hotel in 1990.

If late-night comedians found gold in his failings, Barry’s consituents celebrated him as their well-intentioned, if flawed, champion, his ups and downs and various quests for redemption reflecting their own.

“If there was such a thing as a black Jesus, Marion was that,” said Barbara Morgan, a civic activist who lives east of the Anacostia River and who knew Barry for a half-century. “He was all about doing for people who were downtrodden. He knew what it was to be on the low rung of the totem pole.”

Morgan recalled running into Barry last month at a neighborhood CVS and seeing that he had filled his cart with macaroni and cheese and a container of ice cream. As often was the case, she scolded him about his diet.

“Barbara Morgan, you fussin’ again?” Barry responded.

Of course he was incorrigible, Morgan said, but his friends and constituents watched out for him because he inspired loyalty with his advocacy for the poor and creation of a summer jobs program that benefited generations of young Washingtonians.

“He gave them the opportunity to pull themselves up by their bootstraps and do something positive,” she said. “He never harmed anybody. If he did something, he did it to himself.”

Rev. Willie Wilson of Union Temple Baptist Church said his friend, Marion Barry Jr. who died early Sunday at age 78, will be remembered by many. (Victoria St. Martin/The Washington Post)

From the White House to city hall, Washington’s political establishment commemorated Barry’s passing with statements that often alluded to the varying trajectories of the former mayor’s life.

President Obama, golfing in Las Vegas, described Barry as a “sharecropper’s son” who “came of age during the civil rights movement” and who “put in place historic programs to lift working people out of poverty, expand opportunity and begin to make real the promise of home rule.”

“Through a storied, at times tumultuous life and career,” Obama said, “he earned the love and respect of countless Washingtonians.”

Barry died at United Medical Center in Southeast Washington at 1:46 a.m., according to a hospital spokeswoman. Feeling ill hours before, he had visited Howard University Hospital, which then released him.

An autopsy found that Barry had died from hypertensive cardiovascular disease, with kidney disease and diabetes contributing.

Mayor Vincent C. Gray (D), in an interview, recalled how he had sat at Barry’s bedside in February as the former mayor was gravely ill and “watched him basically resurrect right before my very eyes.”

When he heard Barry was back in the hospital Thursday, Gray said, he thought, “If anyone is going to get past this it’s Marion Barry.”

“I just can’t get over it that they weren’t able to resuscitate him,” Gray said. “Just like that, he was gone.”

Mayor-elect Muriel E. Bowser (D), whose father worked on Barry’s mayoral campaigns, arrived at the hospital around the time Barry died. She described herself as shocked by his death and said he had been “a part of my family’s life for decades.”

It was during Barry’s early career as a leader of the Student Nonviolent Coordinating Committee that he met Del. Eleanor Holmes Norton (D-D.C.), who said he had written “his signature boldly on his own life” and “on the life of the nation’s capital.”

“Many took his struggle to personify in some way their own,” Norton said, “endearing him and making him a larger-than-life figure.”

Another longtime friend, D.C. Council member Anita Bonds (D-At Large), described Barry as a “political genius” who could “turn the cheek, forgive and move forward no matter the adversity.”

Joseph diGenova, who was U.S. attorney for the District in the late 1980s when Barry’s administration spun out of control, said, “As a Catholic, I would wish his soul well and hope the Lord is forgiving as he always is.” But he also said that no one should forget that Barry “created and left an incompetent bureaucracy with corruption and inefficiency as a hallmark.”

“He destroyed public confidence in the drug war by using cocaine in the middle of a cocaine epidemic,” he said. “The image of the District of Columbia in the United States has never recovered from his stewardship, and it is not a good one.”

As morning began Sunday, Washingtonians learned of Barry’s death as they ate breakfast, shopped for groceries and attended church services. At the American City Diner near Chevy Chase Circle, owner Jeffrey Gildenhorn announced the news on the outdoor marquee: “Marion Barry, 1936-2014.”

“I thought it was just fitting and proper that I put his name up,” said Gildenhorn, a Barry friend for decades. “People came in and said, ‘That was very nice what you did.’ ”

At Eastern Market, where shoppers bought food and crafts from local vendors, the chatter about Barry often touched on his more controversial moments.

“It’s the end of an era possibly, whether for good or for bad,” said Jennifer Rankin, 32, who acknowledged that “crack” and “civil rights” are the two phrases that come to mind when she thinks of Barry. “In his past, he was so influential in so many wonderful ways. But lately, he seems to represent cronyism and not getting anything done.”

On the city’s eastern edge, dozens of mourners Sunday night gathered outside Barry’s Southeast Washington home for a candlelight vigil that ended at the Big Chair, a D.C. landmark.

In Congress Heights, residents were planning to gather to watch a previously scheduled showing of Oprah Winfrey’s recent interview with Barry.

By early afternoon, patrons had packed into the Players Lounge in Congress Heights, where Barry liked to eat liver and onions, drink the occasional margarita, and pose for pictures that ended up on the bar’s wood-paneled walls.

Georgene Thompson, Players’ co-owner, sat at the bar, looking through photos of herself and the former mayor.

“My husband told me Mr. Barry died, and I said, ‘No, he can’t be dead,’ ” she said. “Then I saw it on my TV screen.”

Near Minnesota Avenue and Benning Road NE, Shawn Johnson, 47, was selling Redskins T-shirts and talking about the times she had seen Barry going into his Anacostia office, past a waiting room filled with residents applying for food stamps.

“People would stand up and start applauding, they would start to chant his name,” Johnson said. “I don’t know if a bigger thing can happen in Washington for people who’ve lived here.”

At Union Temple Baptist Church in Southeast, the Rev. Willie Wilson, a longtime Barry ally, said he had been at Barry’s bedside and had comforted friends and family members until 5 a.m. Wilson equated Barry’s death to a giant tree falling in the forest.

“You can feel the tremors all around,” Wilson said. “He was always able to rise. People were so surprised that he was gone because so many times he was down and he got back up.”

The Rev. Anthony Motley, a friend of Barry’s for 33 years, also was at Barry’s bedside, telling him he loved him and, even in death, rubbing his feet, as he often did to help with his circulation.

“Those of us who were close to him, that’s what we would do,” Motley said. “It’s like losing a family member, someone you could relate to, someone you could talk to, someone who was concerned about you.”

Their last extended conversation was in October, the pastor said, when he lectured Barry to cut back on his schedule and watch his diet.

“Yes, Tony, I know,” Barry responded, an answer that did little to ease the pastor’s concern.

His death, Motley said, is especially difficult for the city’s neediest neighborhoods, where residents could count on the former mayor to defend their interests.

“Who’s going to advocate for the poor?” Motley asked. “Who is going to stay vigilant when it comes to what should be cut in the budget? Who will make sure the most vulnerable are not so negatively impacted?”

Barry, he pointed out, never anointed a successor.

“He had some standards in that area,” the pastor said. “He was way above the crowd when it came to loving the people.”

Aaron Davis, Hamil R. Harris, Arelis Hernández, Miles Parks, Robert Samuels and Victoria St. Martin contributed to this report.