D.C. Mayor Vincent Gray, left, greets former mayor and current Ward 8 Councilman Marion Barry, right, on stage before Barry's endorsement of Gray’s re-election at the Matthews Memorial Baptist Church in Washington. (John McDonnell/The Washington Post)

Mayor Vincent C. Gray moved Wednesday to shore up his base of longtime city residents and African American voters, enthusiastically accepting the endorsement of Marion Barry in a long and sometimes fiery news conference held in Barry’s home ward.

Gray (D) enjoys close relations with the former four-term mayor, who now serves as the D.C. Council member for Ward 8. Gray spent hours at Barry’s bedside during a recent illness, and the two have been simpatico on most issues.

But Gray, a self-styled “one city” conciliator, has kept Barry (D) at some distance politically, trying to keep that image separate from Barry’s reputation for bombastic and often divisive rhetoric. Four years ago, for instance, Barry campaigned in support of Gray’s first run for mayor, but he never delivered a formal endorsement.

There was no equivocation, however, Wednesday afternoon in the basement of Matthews Memorial Baptist Church, where Barry made an unambiguous case that Gray was the best choice to protect the interests of longtime black residents.

“It’s my pleasure and my honor to endorse Vince Gray for mayor,” Barry said. Gray said he accepted the nod “absolutely, heartily.”

“Now is not the time to elect a mayor for on-the-job training,” said Barry, who remarked on the complexity of the city’s $12 billion budget. “We don’t need an amateur trying to manage this money.”

Barry, 78, praised Gray’s efforts on local hiring, affordable housing and even snow removal. And he addressed allegations of wrongdoing leveled at Gray this month by businessman Jeffrey E. Thompson, who, in the course of entering a guilty plea in federal court, said the mayor was aware of hundreds of thousands of dollars secretly spent on his behalf in 2010. Gray has denied wrongdoing.

“I know Vince Gray is a man of integrity,” Barry said. “I know Vince Gray is not about taking taxpayers’ money. I know that Vince Gray is not about breaking the law. And so I feel comfortable sitting here beside him.”

He added, “I know about how the U.S. attorney works; I know their tactics,” a reference to investigations that culminated in Barry’s 1990 arrest on drug charges. “In America, you’re supposed to be innocent until you’re proven guilty. . . . Also, I know the climate in this city right now is that you’re guilty until you’re proven to be innocent. That’s not right.”

That note of support won cheers from a crowd of several dozen supporters, including George Brown, a 65-year-old retired Army sergeant who lives in Southeast Washington.

“Mr. Barry is still well liked and influential,” Brown said. “He’s a man who can produce votes. The mayor is going to win. Polls don’t matter — it’s the people out in the community.”

Gray led in polls taken before Thompson’s guilty plea, opening a significant lead over his closest D.C. Council challengers in the Democratic primary. But it remains unclear how much the allegations might have harmed his reelection prospects. Barry on Wednesday acknowledged “some slippage” among Gray’s base since 2010.

One of his leading challengers, D.C. Council member Muriel Bowser (Ward 4), has made an aggressive play for votes in Barry’s ward and other majority-black neighborhoods, opening a field office in the Anacostia neighborhood and winning an early straw poll in Ward 8.

But J.R. Meyers, a political consultant who attended the endorsement rally, said the Barry endorsement could be a “game changer” for Gray. “The people [Barry’s] talking to . . . they don’t go to straw polls. They just follow his suggestion.”

Barry’s endorsement came less than two weeks before the April 1 primary. It represents an implicit acknowledgment that Gray’s hopes for a second term lie in mobilizing black voters rather than engaging in a broader effort to sway voters across the city. Barry, according to Washington Post polling done in 2012, is viewed favorably by roughly half of city residents. But his popularity is much higher among black residents than white residents.

Gray said the endorsement did not undermine his long-standing “One City” theme of racial and class unity. “I want the vote of everybody in the District of Columbia now,” he said. “I don’t discriminate in terms of where the vote should come from. . . . To conclude that Marion Barry’s appeal is just to Ward 8 is inaccurate. Marion Barry appeals to people across the District of Columbia.”

Barry was more blunt: “This city, as most urban cities, is divided racially and class-wise. I didn’t create it. Vince Gray didn’t create that. . . . What we have to do is have an ideal of trying to bring everybody together, as Mayor Gray has tried to do, but the reality is that Washington has become a city of the haves and have-nots.”

He added, “I think it’s up to white people to be more open-minded. Blacks are more open-minded than they are.”

Barry delivered the endorsement two weeks after he ended a long stint of hospitalizations. Although he walked into the church meeting room with assistance, he spoke in a strong voice over the course of an hour. He said his health problems may prevent him from being as active on the campaign trail as he might like, but he pledged to be active. “I’m not going to imperil, jeopardize my health for anybody,” he said. “But I’m going to be there when I’m needed.”

At Barry’s side was his 33-year-old son, Christopher Barry, who said his father had asked him to speak in support of Gray.

“I’ve seen he displays many Barryesque-like qualities,” Christopher Barry said. “There’s only one mayor for life, you know, there’s only one Marion Barry, but Vince Gray has shown dedication to the people of Washington. . . . Just like Marion Barry did, he can stand up to adversity and display effective leadership in times of controversy.”