Mayor-elect Martin J. Walsh
said Tuesday that he wants Boston to pull out of a controversial federal initiative designed to identify illegal immigrants because he believes too many people are detained for nonviolent offenses.

The Secure Communities program allows the Department of Homeland Security to access fingerprints taken by local police, which federal officials can check against federal immigration databases. Those who are in the country illegally can then be deported.

Asked whether he would continue to enforce the program as mayor, Walsh responded: “If we can get around it, I won’t.”

“People that are getting pulled over — I don’t think that, necessarily, we have to bring in immigration for that,” Walsh told reporters at a Thanksgiving dinner for immigrants at the State House.

The federal government says it prioritizes for deportation those who pose the greatest threat to public safety, based on their criminal histories. But a Globe analysis this year suggested that federal immigration officials are deporting more immigrants in Massachusetts for civil violations than for serious crimes under the program.

Walsh’s opposition to Secure Communities represents something of a shift from Mayor Thomas M. Menino’s stance. Under Menino, Boston piloted Secure Communities in 2006, and the program was expanded nationally in 2008.

Several hours after Walsh made his remarks, his spokeswoman, Kathryn Norton, acknowledged that the mayor-elect would not have the authority to end Boston’s participation in the program, because it is a mandatory federal initiative.

“As we understand it, there’s no authority to opt out,” Norton said. “Honestly, it remains to be seen what we’re able to do in the role of mayor of Boston.”

Last year, officials expanded the program in Massachusetts, despite strong opposition from Governor Deval Patrick.

Gillian M. Christensen, an agency spokeswoman, said federal officials focus on “priority individuals such as convicted criminals and other public safety threats, as well as those who repeatedly violate our immigration laws.”

“The federal government alone sets these priorities and places detainers on individuals arrested on criminal charges to ensure that dangerous criminal aliens and other priority individuals are not released from prisons and jails into our communities,” she said in a statement.

Walsh, the son of Irish immigrants, said that if he cannot end Boston’s participation in Secure Communities, he would seek to “soften” its impact by pushing for state legislation that would limit Massachusetts’ participation in the program.

Walsh said he supports a bill known as the Trust Act that would allow local police to ignore requests from federal immigration officials to detain illegal immigrants, unless those immigrants have committed major crimes.

“Law enforcement, in particular, needs to be able to build relationships of trust with immigrant communities, and they can’t do that with the fear of deportation hanging over the relationship,” Norton said.

Versions of the bill have been enacted recently in California and Connecticut.

Although immigration was not a major focus of Walsh’s campaign for mayor, his remarks on Tuesday were not the first time he has spoken out on the issue.

As a state representative in 2006, he voted for a bill that would have granted in-state tuition rates at public colleges to illegal immigrants who graduated from Massachusetts high schools. “He’s always been supportive of immigrants, including undocumented immigrants,” said state Senator James B. Eldridge
, an Acton Democrat, and lead sponsor of the Trust Act.

Menino’s position on Secure Communities has shifted. Initially, he and other city officials strongly defended the program, saying it could help reduce crime in a city that has struggled with gun violence.

Then, in an abrupt reversal in 2011, Menino threatened to withdraw Boston from the program unless federal officials limited their deportation efforts to only those immigrants who committed serious crimes.

“The way it was written does not serve local law enforcement in their efforts for community policing,” Dot Joyce, a Menino spokeswoman, said Tuesday. “While it may be a good program on the federal side, without changes, it does not work locally.”

Boston’s acting police commissioner, William Evans, echoed that stance. “Commissioner Evans agrees that to have an effective community policing effort you must have the trust of the people,” said his spokeswoman, Cheryl Fiandaca. “He has been supportive of Mayor Menino in his continued efforts to change the policies around Secure Communities.”

Immigrant activists said they were pleased that Walsh had clearly stated his opposition to Secure Communities.

“The program, unfortunately, is mandatory now,” said Patricia Montes
, executive director of Centro Presente, an immigration advocacy group in Somerville. “But he has the power at least to question the program, and to work with the immigrant community to make sure the program is not affecting people who don’t have criminal records.”

But Thomas O’Loughlin
, the police chief in Milford, said it would be a mistake to withdraw from the program.

His town has been a hotbed of debate over illegal immigration since 2011, when an illegal immigrant who was driving while drunk struck and killed a motorcyclist named Matthew Denice
. “It doesn’t focus on the person that came here for a better life, who came to here to work hard and was doing tough jobs. Why focus on them?” O’Loughlin said. “If he’s a repetitive, serious offender, then that’s the person they should focus on. I don’t want that person living next to me.”

BostonGlobe.com complimentary digital access has been provided to you, without a subscription, for free starting today and ending in 14 days. After the free trial period, your free BostonGlobe.com digital access will stop immediately unless you sign up for BostonGlobe.com digital subscription. Current print and digital subscribers are not eligible for the free trial.

Thanks & Welcome to Globe.com

You now have unlimited access for the next two weeks.

BostonGlobe.com complimentary digital access has been provided to you, without a subscription, for free starting today and ending in 14 days. After the free trial period, your free BostonGlobe.com digital access will stop immediately unless you sign up for BostonGlobe.com digital subscription. Current print and digital subscribers are not eligible for the free trial.