On a cold, gloomy day in February of last year, a group of protesters showed up at the U.S. attorney’s office here and demanded to see a prosecutor who had brought a terrorism case against a young Muslim man.

They had spent the week pursuing Aloke Chakravarty, an assistant U.S. attorney, bombarding him with faxes and phone calls and accusing him of what may be the serious affront to a government lawyer: targeting Muslims because of their faith.

But it was not just any prosecutor who had aroused the ire of some in Boston’s Muslim community. Chakravarty had shaped his career in part around protecting the civil rights of that very group, feeling it had been unfairly targeted by bigotry. And he had been leading the Justice Department’s efforts to create a new relationship with Muslims throughout the region.

He also was the man who had prosecuted several Muslims in terrorism investigations. Now, he found himself under attack.

A decade after the Sept. 11, 2001, terror strikes, the dilemma for Chakravarty and other federal officials — searching for homegrown terrorists without violating the rights of Muslims — remains as sharp as it was in the immediate, chaotic aftermath of the attacks.

The federal government’s domestic counterterrorism efforts have scaled up dramatically, largely through a transformation of the FBI into an intelligence-driven agency and a large increase in the number of agents devoted to fighting terrorism. Justice Department and FBI officials say they have helped prevent a second major terror attack on American soil and arrested numerous would-be terrorists.

The government’s efforts have relied in part on a more trusting relationship with Muslims — a particular focus in the Obama administration — and many leaders in the community have been open to that. But others have complained about federal law enforcement and its investigations, surveillance and arrests of Muslims, accusing officials of targeting the same community they are trying to cultivate.

It is one of those arrests and prosecutions that has complicated Chakravarty’s dual role: From his office next to Boston Harbor, he has taken the lead in trying to build a better rapport with Muslims. But he also is prosecuting the terror case against Tarek Mehanna, a local Muslim whose trial is scheduled for early October.

In meetings with Muslims, Chakravarty is unfailingly polite and solicitous. In court, he is the tough post-Sept. 11 prosecutor, endorsing tactics that are considered routine by law enforcement officials but have infuriated many Muslims, including the use of cooperating witnesses in their community.

Arguing in court that Mehanna should be held without bail, Chakravarty described the thread between the accused and those around him.

Mehanna committed his crimes “often from the confines of his own home,’’ Chakravarty said, “often with the assistance, with the knowledge of people in this very same community.”

Cultivating outreach

In the Boston area, tensions between federal law enforcement and Muslims, who number roughly 100,000, were triggered by the 2001 attacks, when 10 hijackers boarded two planes at the city’s Logan International Airport and crashed them into the World Trade Center.

That prompted a crackdown by the FBI’s Boston office, whose jurisdiction stretches from Rhode Island to Maine. Agents fanned out, rounding up local Muslims for questioning, according to Boston area Muslims. It was part of a nationwide sweep that ultimately brought in hundreds of people, most of whom never faced terrorism-related charges.

“There was huge investigative activity after Sept. 11,’’ said Richard DesLauriers, special agent in charge of the FBI’s Boston division.

Aloke Chakravarty watched the crackdown with unease from the Massachusetts attorney general’s office, where he was an assistant attorney general, and decided to do something. He pursued a job at the Justice Department, convinced he could help strike “that balance between civil liberties and how invasive law enforcement can be,’’ he said.

“It became clear that people from certain backgrounds, largely Arab, Muslim, South Asian backgrounds, had shortly after the attacks been treated differently, both in the public eye as well as literally in terms of the enforcement of our laws,’’ Chakravarty said in an interview.

When he arrived in Boston in 2005, law enforcement officials had already come to appreciate the need to reach out to Muslims. Justice and FBI officials had been speaking at mosques and organizing meetings with Muslim leaders, trying to form bonds and smooth over the resentment that had built up.

The hope was that if Muslims trusted federal agents, they would be willing to alert the government to possible threats. And, especially after the terror attacks, the effort was aimed at protecting Muslims amid a spike in prejudice against them.

It was a personal mission for Chakravarty, 38, a graduate of Baltimore’s Johns Hopkins University who speaks with a scholarly air and has a trim goatee flecked with gray. Known as “Al,” he is uncomfortable discussing personal details and would not disclose his religion. He did say he was born in South Carolina, where, he notes with pride, the governor, Nikki Haley, is Indian American.

It was presumably his Indian heritage that, years earlier, prompted a defendant to blurt out across a courtroom the word “terrorist” when he saw Chakravarty, who at the time was a prosecutor in Middlesex County near Boston.

When he joined the U.S. attorney’s office, law enforcement’s attempt to work with Muslims was troubled. The FBI was about to rescind funding to help start a Boston-based program to coordinate efforts to reach out to Muslims and Arab Americans nationwide.

The agency cited budget problems, but Deborah Ramirez, a Northeastern University professor who designed the program, said officials also “got a lot of political push-back and decided they couldn’t move forward. . . . There were some who said you shouldn’t be sitting down with these people, you should be treating them as suspects.’’

It was unclear whether the meetings in Boston would continue until Chakravarty, working with Muslim leaders, pushed to keep things going. It was, he recalled, a “watershed moment where there was no funding, no infrastructure, no governmental doctrine or mandate” for what he saw as a critical effort.

Since then, the efforts have expanded. Chakravarty’s boss, U.S. Attorney Carmen M. Ortiz, is focused on building a relationship particularly with the largely Muslim Somali community. The head of the FBI office, DesLauriers, convenes his own meetings with Muslims and other minorities.

And the monthly meetings that Chakravarty had spearheaded and often runs, known as “Bridges,” have become established, routinely drawing high-ranking officials, including Ortiz, representatives of the FBI and numerous Muslim leaders. The conversation can range from airport security to visits from FBI agents, and, in a recent session, how to combat anti-Islamic stereotypes.

A regular participant is Abdillahi Abdirahman, a coffee shop owner who represents the city’s roughly 4,000 Somali Muslims.

Abdirahman, who also meets on his own with the FBI, says he often complains during the meetings about visits from agents to Somali homes and businesses. FBI agents have come to his coffee shop at least 15 times in the past two years, he said. They ask if he knows anyone affiliated with al-Shabab, a Somali Islamist extremist group that is linked to al-Qaeda. They are polite and professional, he said, and always take notes.

Still, he added, “they are harassing the community.’’

His meetings with FBI supervisors are cordial, he said. They listen to his concerns and offer to help. They too quiz him, scribbling in their notebooks. But despite the kind reception from supervisors, he said, the agents keep coming back.

“The people at the top say ‘we’re partners, we care,’’’ said Abdirahman. “But the message from management and the message from the soldiers on the field doesn’t totally connect.’’

And, he said, some people in his own community are suspicious of him because of the meetings.

Ziad Ramadan, another Muslim leader, said he meets with FBI counterterrorism agents a few times each year at the Worcester Islamic Center, about 40 miles from Boston, where he sits on the board. They sit in his second-floor office, ask how they can help the mosque, then question him about his congregation.

“They ask, ‘Do you know this guy, does he go to the mosque?’ ’’ Ramadan said.

He believes agents are profiling Muslims but says he is grateful for their assistance. “We’re on the same team, ’’ he said. “The most likely terrorism case will come from the Muslim community.’’

Yet Ramadan cannot reconcile his warm relationship with the FBI with the terror case the agency built against Mehanna. Mehanna belonged to Ramadan’s Worcester mosque and taught at the adjoining Islamic school. His arrest and treatment has outraged Ramadan.

“This guy is not a threat, I would bet my life on it,’’ Ramadan said just after the close of a recent midday Thursday prayer. “They have to lock him up 23 hours a day? There’s no justification for that.’’

“I’m completely perplexed,’’ he added.

Controversy around Mehanna case

Mehanna, 28, grew up in Sudbury, a well-to-do Boston suburb, the son of a professor at the Massachusetts College of Pharmacy and Health Sciences. The younger Mehanna — described by friends as a devout Muslim but by prosecutors as an aspiring terrorist — obtained his doctorate from the same school and worked as a pharmacy intern at a local Walgreens.

On Nov. 8, 2008, FBI agents arrested him as he was boarding a plane at Logan International for Saudi Arabia. Initially, he was charged with lying to agents about his knowledge of the activities of a former Boston area Muslim who was convicted on a terrorism charge.

Mehanna was out on bail when he was arrested again in October 2009 on new charges — that he tried to attend a terrorist training camp in Yemen and worked for al-Qaeda online by translating and distributing jihadi texts intended to incite violence. Now he is held on 23-hour-a-day lockdown, he has said in letters from prison.

Chakravarty, Ortiz and the FBI declined to discuss this or any terror case. But in a 75-page memo arguing for Mehanna’s detention, Chakravarty and Assistant U.S. Attorney Jeffrey Auerhahn quoted evidence seized from Mehanna’s computer in which he allegedly expressed his love for Osama bin Laden and ridiculed the burned bodies of U.S. servicemen killed in Iraq as “Texas BBQ.’’

The November 2009 filing included an FBI affidavit that said Mehanna, a friend and a government informant had discussed a plan — inspired by the D.C. area snipers — to shoot up a shopping mall. (That allegation is a particular source of anger for Mehanna’s supporters because it is not included in the indictment .)

The FBI said the group tried to acquire automatic weapons but ultimately abandoned the plot.

The government filing also included a photo of Mehanna and two friends visiting Ground Zero in Manhattan. Mehanna was pointing his finger toward the sky. In court, Chakravarty later said that Mehanna’s “grin from one side of his ear to the other” in the photo indicated his support for “Osama bin Laden’s mission.’’

Mehanna’s lawyers have argued that portions of the charges violate his First Amendment rights to free speech. And terrorism experts say it is one of the first U.S. cases to attempt to criminalize Internet translations in support of a terrorist group.

Prosecutors say Mehanna is being prosecuted for his crimes, not his beliefs, and a judge recently declined to throw out some of the allegations on First Amendment grounds.

Hundreds of supporters have packed Mehanna’s court hearings, and backers have created a Facebook group with more than 4,000 members. The supporters’ Web site accuses the government of fabricating the charges in retaliation for Mehanna’s refusal to become an FBI informant.

Last year, the Tarek Mehanna Support Committee focused on the prosecutor. Members called Chakravarty and sent him faxes and letters condemning the case as “an outrageous example of religious persecution and institutional abuse of power.’’

Then they came to his office.

“Chakravarty is known for saying this issue is important to him because he doesn’t want to see people targeted,” said Laila Murad, an organizer of the Mehanna supporters. “Based on his actions, we don’t really see that as the truth.’’

Among Mehanna’s backers is Ahmed Elewa, a graduate student and former outreach director for the Muslim American Society of Boston, who had been given a Justice Department award for his role in promoting good relations between Muslims and law enforcement. Three years after receiving the award — and posing for a photo next to Chakravarty — he wrote a blog post saying he was “alarmed” by the prosecutor’s arguments in the Mehanna case.

“I don’t believe that sympathizing with an enemy of the United States is a crime,” he said in an interview.

In 2009, while prosecuting the Mehanna case, Chakravarty sought out an ever-wider circle of Muslims. He wanted, in part, to understand the sources of radicalization in the Islamic community.

That’s when he called Nasser Weddady, Boston-based civil rights outreach director for the American Islamic Congress, and said he wanted to meet.

At a Starbucks near Weddady’s office in the Back Bay section of Boston, Chakravarty explained his dilemma.

“I want you to understand what we are grappling with. You know and I know there is a problem” with radicalization in the Muslim community, Weddady quoted Chakravarty as saying that day. “But we are trying to go about this in a sensitive way. We won’t infringe on anybody’s civil liberties, but at the same time, it’s our duty to protect this country.’’

They have gone on to meet more than a dozen times, discussing extremism among Muslim youth, the role of the Internet and the underpinnings of radical jihadism. “He’s clearly been reading about the subject, about violent Islamists, the Muslim Brotherhood,’’ Weddady said. “He’s trying to understand the mind-set.’’

From the start, Chakravarty was upfront: He was prosecuting Mehanna but couldn’t discuss the case. “That’s why I started trusting him,’’ Weddady said. “He was sincere and genuine.’’

A balancing act

At the federal offices in Boston, Chakravarty and FBI officials are balancing many strands in their complex relationship with Muslims.

Cynthia M. Deitle, who runs civil rights enforcement efforts for the FBI office here, finds herself walking a fine line. While she is seeking out victims of civil rights abuses, she said, she sometimes fields complaints from Muslims about visits by counterterrorism agents. She tries to assuage the concerns but also feeds tips gained from those sessions to her colleagues on the terrorism side.

“How do we balance these two programs?” she said. “It’s a continual challenge, both on the terrorism side and on my side, to keep encouraging people, especially in that community, to talk to us. And to trust us.’’

Even as Chakravarty and his colleagues in the U.S. attorney’s office prepare for the Mehanna trial, they are trying to expand the Bridges program to other parts of the state. And Chakravarty made a point to send someone from the Justice Department to reassure Brandeis University students near Boston after a Muslim place of worship was vandalized.

All of the effort to build relationships in the Muslim community, he said, “helps us engage in enforcement actions in a more efficient fashion, so instead of casting a wide net . . . you’re able to be much more selective. . . . It does help us in a tremendous number of ways.’’

The prosecutor rejects any concerns about his dual roles.

“I think the media creates this artificial distinction of it being an either/or proposition, of being able to be an enforcer of the law and also do outreach,’’ Chakravarty said. “All communities, especially a sophisticated immigrant community, recognize that we wear the hat of the law enforcer.’’

And he makes clear that his primary focus is his day job. Because he can’t talk about the Mehanna case, he said he can’t discuss his feelings about being targeted by Mehanna’s supporters.

“I feel comfortable, at least in the cases where I have a role, that we are protecting civil rights as we enforce our national security,’’ he said.