Former Maryland Gov. Martin O'Malley, center, meets with residents Tuesday, April 28, as hundreds of National Guardsmen patrolled the streets amid rioting. (Matt Rourke/AP)

When Martin O’Malley makes his expected announcement for president later this month, he plans to do it in riot-scarred Baltimore.

“I wouldn’t think of announcing anyplace else,” O’Malley, the city’s former mayor and Maryland’s former governor, said Sunday during an appearance on NBC News’s “Meet the Press,” calling the events of the past week “a wake-up call for the entire country” that would become a central part of his campaign.

He may have little choice. Despite a tumultuous week for Baltimore and for O’Malley — and the risk of staging an announcement in a place that has been fraught with unrest — there’s another risk as well: being seen as running away from a drama in which O’Malley has been cast as a central character.

Perhaps because of that, O’Malley appears to be embracing it.

The Democrat cut short a trip to Ireland last week after the rioting broke out, inserting himself into the chaos surrounding Freddie Gray, the 25-year-old ­African American whose death in police custody resulted in indictments Friday of six officers.

Though O’Malley no longer has any official role — he left City Hall eight years ago, and his tenure in Annapolis ended in January — he surfaced amid the protesters, visited churches, participated in a food drive and drove himself around the city where he lives trying to reconnect with old friends and allies.

The effort brought political peril; O’Malley was peppered with questions about the “zero-tolerance” policing he brought to Baltimore, which, while driving down crime, critics have said contributed to the community distrust that erupted after Gray’s funeral.

But O’Malley has stayed the course. By the end of the week, he was incorporating Baltimore’s unrest into his campaign narrative and arguing that the upheaval highlighted the need for a national urban agenda on issues beyond policing.

“There are people in whole parts of our cities who are being totally left behind and disregarded,” O’Malley said during the Sunday morning TV appearance. “They are unheard. They are told they are unneeded by this economy. . . . We need to stop ignoring especially people of color and [acting] like they’re disposable citizens in this nation. That’s not how our economy’s supposed to work. It’s not how our country works.”

Much of O’Malley’s week was unscripted, and some of it was awkward. He was heckled at times and was met with indifference by some of his former constituents who saw his presence as a distraction or opportunism. But O’Malley stood firm, defending his policies in numerous national media interviews.

On Wednesday, O’Malley and a handful of aides pulled up to a food giveaway at the parish hall of St. Peter Claver Catholic Church in Sandtown, the impoverished neighborhood where Gray had lived.

Even before introducing himself to organizers, O’Malley — his sleeves rolled up and tie tucked in — had picked up a couple of cartons of macaroni and cheese and joined a racially diverse group of volunteers walking in the food.

Some hugged O’Malley and posed for pictures as he handed out bags of kale and offered preparation tips. (“You chop it up,” he told one skeptic. “It’s like spinach.”) One woman asked O’Malley to hold her child. Another exclaimed: “Yay, Martin O’Malley!”

Others were outwardly polite but privately critical of O’Malley’s leadership.

“He’s walking into the aftermath of his legacy,” said Claire Landers, a Baltimore County resident helping with the food drive.

The following day, O’Malley’s travels in the city included a stop at the Dawson Safe Haven Community Center in East Baltimore, where in 2002 the Dawson family of seven was murdered when drug dealers firebombed their home in retaliation for calls to the police about their activities.

The scene offered a reminder of what O’Malley had faced as mayor — and what had propelled him into office in the first place: a public fed up with horrific crime and eager to see a crackdown on the drug dealers who had taken over so many of the city’s neighborhoods.

Already a long shot in a Democratic field that includes Hillary Rodham Clinton, O’Malley, analysts said, has no alternative but to tackle head on what’s happened in his home town if he hopes to gain traction.

“He’s got to show he’s not afraid of his legacy in Baltimore,” said Mike Morrill, a longtime Democratic strategist in Maryland. “If he tries to disconnect from Baltimore, people will tie it to him like a lead weight, and it will sink him.”

Some pundits went even further, declaring O’Malley’s presidential ambitions dead on arrival after this week. But on Sunday, he showed no signs of backing away.

“I am more inclined and more deeply motivated now to address what’s wrong with our country and what needs to be healed and what needs to be fixed,” he told “Meet the Press” host Chuck Todd.

As O’Malley has traveled the country preparing to run for president, he has made a populist pitch — pledging to reform Wall Street and break up the big banks — and he recounts a litany of liberal accomplishments as governor, including the legalization of same-sex marriage, the repeal of the death penalty and a number of measures to help immigrants.

Although he is nearly a decade removed from Baltimore City Hall, O’Malley’s record as a crime-fighting mayor also has been a central part of his pitch. When he was elected in 1999, he says, Baltimore was the “most violent, the most addicted and the most abandoned city in America.” Over the following decade, it went on to experience the steepest drop in violent crime in the country.

O’Malley’s challenge now is to reconcile those claims against the images of burned cars and angry protesters that emerged from Baltimore last week. Activists in early presidential nominating states said that, if nothing else, his time as mayor is bound to be scrutinized more now.

“People certainly know more about Baltimore, or think they know more about Baltimore, than they did a week ago,” said Nathan Blake, a Democratic activist in Iowa who is a former Maryland resident. “But I feel like we’re still in the middle of it, and all sorts of things could still happen.”

In New Hampshire, Eric Zulaski, who is looking for a Democratic alternative to Clinton, said that he wants to hear candidates discuss policing issues now.

“It’s sort of been in the ether, like the whole war on drugs,” said Zulaski, who does public relations work for a Quaker organization and was attending an event for another Democratic hopeful, Sen. Bernie Sanders (I-Vt.). “It didn’t used to be a Democratic issue, but they have made it one for themselves.”

One potential benefit for O’Malley from the Baltimore events is the near certainty that more people will tune in if and when he makes his presidential ambitions official. If he capitalizes on the attention with a compelling message, it could help him, said Thomas F. Schaller, a political science professor at the University of Maryland Baltimore County.

“This is how presidential candidates are either forged or destroyed,” Schaller said. “He’ll be in the spotlight now more than he would have been. There’s really a danger and an opportunity.”

O’Malley also carries the advantage of being better versed in urban issues than his potential competitors, said Steve Kearney, a former senior aide.

“Every day as mayor for seven years, he woke up and did this — the issues of policing and race, justice and injustice, economic opportunity,” Kearney said. “And he continued to do that as governor.”

Violent crime fell sharply during O’Malley’s mayoralty. The number of homicides declined by 16 percent, part of a wider decline across much of the country. At the same time, the number of arrests in Baltimore soared, reaching 108,447 in 2005.

Although he won praise in many quarters, some civil rights and community leaders said that the frequent arrest of black men — many of them repeatedly and often for relatively minor offenses — eroded relations between police and the community. Two of the six officers indicted Friday were hired during O’Malley’s tenure.

In his appearances through the week, O’Malley reminded reporters that he was reelected as mayor by a wide margin after implementing a new style of policing.

“And when I ran for governor, Baltimore was totally in my corner,” O’Malley told reporters outside the Dawson Center.

Several residents, some on foot and some driving by, watched curiously as O’Malley stood surrounded on the street corner in a neighborhood of row homes.

After the media questions ended, one man who approached O’Malley mistakenly thought he was running for Congress.

The man, who introduced himself as Mark Anthony, said he remembered O’Malley as mayor. “You made a difference,” he said. O’Malley shook his hand, and then embraced him.

Aaron C. Davis contributed to this report.