Cameron was accompanied by Massachusetts Gov. Deval Patrick when he visited the makeshift memorial that includes T-shirts, letters, running shoes and other items in the city's Copley Square. The memorial grew in the wake of the April 15 explosions at the marathon finish line that killed three people and injured more than 260.
The United Kingdom, Cameron said, has experienced that sort of terrorism in London and elsewhere and knows to stand up and say terrorists will never win.
"Obviously, what we do for the future, we have to do everything we can to work with law enforcement agencies to maintain our vigilance," Cameron said after walking through the memorial amid tight security. "But, I think, above all, we have to say very loudly, very proudly, very clearly that we are proud to live in a country - whether it is America or Britain - that is a democracy, that loves freedom, that loves diversity, that is a multiracial country and we'll never give in to terrorists."
Cameron is in Boston to offer his condolences and discuss lessons that can be learned from the bombings. The trip follows a White House visit Monday during which the prime minister met with President Barack Obama.
"One of the things we have to do is we have to challenge the poisonous narrative on which they feed, a narrative of violence, extremism, victimhood," Cameron said. "We have to challenge that narrative and that's not the work of months or years, it's the work of our generation, and I'm determined we'll do our bit to challenge it to make sure the terrorists never win and that freedom always does."
The attacks sparked one of the biggest manhunts in Massachusetts, which ended days later when one bombing suspect died after a gunbattle with police and the other, his younger brother, was arrested. The brothers also are blamed for the shooting death of a Massachusetts Institute of Technology campus police officer days after the bombing.
The younger brother is recovering in a federal prison hospital.
"There is always more to do. Look, there is really a vital role for law enforcement, a really vital role for intelligence, there is a tough side to all of this that we have to get right," Cameron said. "But in the end, how do we do it? We do it by standing for the values we believe in, for freedom, for democracy, for the fact we're proud to live in an open and tolerant society.
"It is hard to believe people can do these things to countries like ours when we are freedom-loving, when we are democracies, when we do value people's rights, but these things do happen and we have to fight them and challenge them. That's what I know you are going to do right here in Boston," Cameron said before leaving the site.