British leaders, particularly from the Conservative Party, which Mr. Cameron leads, have mostly been careful to avoid arguments that might expose them to charges of holding racially tinged views since a notorious speech in 1968 in which Enoch Powell, a leading Conservative, warned of “rivers of blood” if nothing was done to curb Caribbean immigration to Britain.

“We have failed to provide a vision of society to which they feel they want to belong,” Mr. Cameron said, speaking of immigrant groups, dominated by Muslims, whose numbers have been estimated in some recent surveys at 2.5 million in Britain’s population of 60 million. Britain’s domestic intelligence service, MI5, has said that as many as 2,000 Muslims in Britain are involved in terrorist cells, and that it tracks dozens of potential terrorist plots at any one time.

Mr. Cameron continued: “We have even tolerated these segregated communities behaving in ways that run counter to our values. So when a white person holds objectionable views  racism, for example  we rightly condemn them. But when equally unacceptable views or practices have come from someone who isn’t white, we’ve been too cautious, frankly even fearful, to stand up to them.”

The prime minister pointed to several steps the government planned that would tackle the rise of extremism. Among these, he said, would be barring “preachers of hate” from visiting Britain to speak in mosques and community centers; stopping Muslim groups that propagate views hostile to values of gender equality, democracy and human rights “from reaching people in publicly funded institutions like universities and prisons”; and cutting off government support for such groups.

The prime minister’s speech came at the end of a week in which Britain’s role as a base for Islamic terrorists as well as the behind-the-scenes pressure applied by the United States for actions that would deal more effectively with the threat have drawn fresh attention.

On Thursday, the government’s official watchdog on antiterrorist issues, Lord Alexander Carlile, issued a final report before retiring in which he said that Britain had become a “safe haven” for terrorists, primarily because of rulings by the European Court of Human Rights, that made it difficult to deport people considered terrorist risks, and other decisions that curbed the application of British antiterrorist laws.

For years, and particularly since the attacks of Sept. 11, 2001, American officials have been frustrated by what they see as an insufficiently robust crackdown on terrorist groups in Britain, which have been identified in Congressional testimony and elsewhere as a leading threat to American security.