In a city whose local government emerged out of decades of protest, D.C. Mayor Vincent C. Gray fits right in.

The 69-year-old Democrat has walked picket lines, marched down Pennsylvania Avenue, organized mass vigils and put his body on the line for a cause, most recently when he was arrested in April during a demonstration against Congress.

Gray, who was raised in a one-bedroom in Northeast, said his life has been defined by his work “on behalf of people who are perceived as the underdog,” from leading the fight to desegregate George Washington University’s fraternity system to a four-decade career in human services.

But like numerous big-city mayors, Gray’s tolerance for activism is being tested by protesters affiliated with the Occupy Wall Street movement, which shows little sign of retreating in the District.

Gray is generally supportive of the cause, but he says he is bewildered by how the movement has ended up known as much for its tents as for its demands.

“What is frustrating for me, and I think of my own causes, is, what is the desired outcome here?” Gray said. “Where are you trying to get to? . . . You see signs that read, ‘End corporate rule.’ Well, how do you do that?”

With Occupy D.C. about to enter its fourth month, Gray is struggling to balance his embrace of protest as a tool for social change and his obligation to run a city where demonstrations present a near-daily challenge to local officials.

“You don’t want to be a hypocrite,” said Gray, a fierce partisan who last year used a derogatory pun to refer to tea party members and who was initially intrigued by Occupy’s young, liberal protesters.

The mayor’s evolving view of the Occupy camps in Freedom Plaza and McPherson Square offer a window into not only his leadership style and political upbringing, but also the challenges protesters face in winning converts to their campaign to reduce income inequality and the influence of corporations.

Gray’s struggle puts him in the company of activist mayors in Los Angeles, Atlanta, Richmond and Oakland, Calif., who in many cases got their start in politics after championing a cause, only to find themselves now pitted against a new generation of political anger.

“This has been very hard for mayors, in particular, to deal with because in most cases it’s not about local issues but takes a very local form in terms of an occupation,” said Craig Calhoun, president of the Social Science Research Council and a New York University professor. “Sometimes local politicians are like movement leaders, but mayors are evaluated on whether the trash gets picked up and not just what is their stance on social justice.”

With both Occupy D.C. camps on National Park Service property, Gray doesn’t face the same stress as some of his counterparts in deciding whether to order police to dislodge the encampments that have defined the movement.

But D.C. police must monitor the sites and track protest marches originating in Freedom Plaza and McPherson Square, responsibilities that Gray said are straining some city resources and piling up police overtime.

In recent weeks, in a series of actions that have angered key business leaders, Occupy D.C. protesters tried to block people from leaving a conservative conference at the Walter E. Washington Convention Center, broke into a vacant city school, staged traffic-snarling demonstrations, and tested patience and security plans at several prominent office buildings and hotels.

In the early days of the protests, D.C. police sought to avoid arresting protesters, adhering to department policy designed to insulate the city from lawsuits while protecting demonstrators’ right to petition the government. But over the past month, police have arrested nearly 100 Occupy protesters, including 62 at a K Street sit-in Dec. 7.

“We want to support the movement, but we are not going to tolerate breaking of the law,” said Gray, who said he cannot quite define acceptable civil disobedience but thinks that Occupy protesters have gone too far.

Gray’s tone toward the protesters has on occasion veered from supportive to scolding, underscoring the tension he and like-minded big-city mayors across the country are feeling in dealing with the Occupy movement.

At times, Gray has appeared as if he could be a father figure to the protesters, including welcoming them to the District as part of his remarks at an annual Christmas celebration at city hall, according to people at the ceremony.

At other times, Gray has come across as a cranky neighbor. Last week, he sent a terse letter to the director of the National Park Service demanding that the city be reimbursed $1.6 million for costs accrued during the protests.

“Gray talks about [protesters] not having a consistent message. Well, what about him not having a consistent message?” said Kristopher Baumann, president of the District’s Fraternal Order of Police local. “You have a mayor who has been arrested for blocking traffic. He’s not in a position to be telling people what is right or wrong at this point.”

But Carol Fennelly, director of Hope House, said Gray has handled the demonstrations “beautifully” because he understands he’s “playing his role” as mayor.

“You have to understand: When people go to get arrested, they need someone to arrest them,” said Fennelly, a veteran homelessness activist whose been arrested more times than she can remember. “He does what needs to be done.”

Earlier in Gray’s life, that meant something different.

In 1963, as a student at George Washington University, he ignored taunts of “no negroes” to become one of the first African Americans to rush a GW fraternity. (He later was president of Tau Epsilon Phi.) And although Gray didn’t immerse himself in the civil rights movement, he participated in the Rev. Martin Luther King Jr.’s March on Washington that year as well.

After being shaken as a young adult when he saw staffers at Forest Haven, a Laurel mental-health institution run by the District, hose down patients like animals, Gray took up a decades-long fight to close the facility, first working as an activist and then as director of the Association for Retarded Citizens.

After being appointed director of the D.C. Department of Human Services in 1991 — a job in which he was both the target of protests and a vocal critic of federal budget cuts — Gray oversaw the court-ordered closure of Forest Haven that year. As founding director of Covenant House for Homeless Youth from 1994 to 2007, Gray organized annual candlelight vigils to help disadvantaged youths learn about political activism.

During his career as a council member and mayor, Gray’s activism has focused on D.C. voting rights, including being arrested on Capitol Hill in April and vocally calling for residents to get angrier about their status.

In a city that won home rule in 1975 after decades of protest, Gray embodies an earlier generation of city political leader for whom protesting was routine. In 1993, then-mayor Sharon Pratt Kelly (D) was arrested in a statehood demonstration on Capitol Hill. In 1985, then-mayor Marion Barry (D) held a city-sanctioned demonstration in which District employees left work to protest apartheid in front of the South African Embassy. Barry’s wife at the time, Effi, was arrested there.

Barry, who was a civil rights youth leader in the 1960s, said the District’s history of activism means Gray should tread lightly when it comes to dealing with Occupy protesters.

“Part of a protest is to make it inconvenient,” Barry said. “When we sat at a lunch counter, we deliberately made it inconvenient for those not giving us justice. I identify 100 percent with Occupy D.C.”

But Gray said he worries that Occupy protesters may have missed their window, becoming co-opted by troublemakers more interested in camping than protesting. And, Gray, like mayors who have moved to break up Occupy camps, said the group has been too slow to identify concrete demands.

“I have done my share of marching in Washington to try to effect change . . . but we knew what we were fighting for, and were able to articulate it,” said Richmond Mayor Dwight C. Jones, a Baptist preacher who ordered police to break up Occupy Richmond’s camp Oct. 31. “When you are talking about economic equality, that is a good thing, but when you start talking about a place to be for 24 hours a day, seven days a week, as mayor, I have to deal with ordinances I have been sworn to uphold.”

For now, Gray remains conflicted.

When asked what he would do if Park Service officials gave him authority over the Occupy D.C. camps, Gray said he would “talk to the people in charge of this movement” before making any decisions.

“If I had a better idea of what they are trying to accomplish, I might have been able to help them get there,” he said.