Islamic State militants could grow strong enough to target people on the streets of Britain unless action is taken, David Cameron has warned.
The PM, writing in the Sunday Telegraph, said a "humanitarian response" to IS was not enough and a "firm security response" was needed.
It comes as Church leaders expressed concern that the UK had no "coherent" approach to tackling Islamic extremism.
IS has seized large parts of northern Iraq and Syria over the summer.
There are also continuing reports of massacres of non-Muslims by the extreme Sunni group, which is seeking to build a new Islamic state spanning Iraq and Syria.
Kurdish forces, supported by US air strikes, said they had recaptured Mosul dam from IS fighters in northern Iraq on Sunday. The Pentagon said it had destroyed or damaged 19 IS vehicles and a checkpoint near the dam.
By Robin Brant, BBC political correspondent
The language is very strong - "a battle against a poisonous ideology" - and the warning is stark - "a terrorist state on the shores of the Mediterranean" - as the prime minister seeks to make the case for Britain returning to Iraq.
After a week that has seen UK military aircraft drop humanitarian aid, David Cameron makes it clear that alone is not enough to defeat IS. He talks repeatedly about Britain using its "military prowess" and military action, alongside diplomacy, to defeat the group.
The talk is tough, but Downing Street insists this is not an escalation. The Ministry of Defence has been reminding people that the UK has played no role in supporting the latest round of US air strikes on IS targets across northern Iraq.
The prime minister's message is as much about home as well as abroad. People walking around with an Islamic State flag "will be arrested", he says. That is a nod to the growing concern about Britons who have gone to fight jihad, in Syria or Iraq, returning home with the intention of carrying on the struggle.
"True security will only be achieved if we use all our resources - aid, diplomacy, our military prowess - to help bring about a more stable world," Mr Cameron said.
"If we do not act to stem the onslaught of this exceptionally dangerous terrorist movement, it will only grow stronger until it can target us on the streets of Britain."
He warned that if IS was able to "carve out its so-called caliphate", the UK would be "facing a terrorist state on the shores of the Mediterranean and bordering a Nato member".
The UK has made aid drops to people stranded in northern Iraq but the prime minister warned a "broader political, diplomatic and security response" was needed, in addition to humanitarian action.
"We need a firm security response, whether that is military action to go after the terrorists, international co-operation on intelligence and counter-terrorism or uncompromising action against terrorists at home," he wrote.
In Britain, the prime minister suggested, anyone "walking around with Isil flags or trying to recruit people to their terrorist cause" should be arrested.
Mr Cameron also made clear that he did not see this as a "war on terror" but as "a battle between Islam on the one hand and extremists who want to abuse Islam on the other".
Speaking on Radio 5 live, communities minister Stephen Williams said any British citizen encouraging people to join IS should face "the full force of the law".
Mr Cameron's remarks come as the Bishop of Leeds warned "many" senior clergy in the Church of England were seriously concerned about Britain's approach to the handling of the Iraq crisis.
The Right Rev Nicholas Baines has written to Mr Cameron asking about the government's overall strategy in response to the humanitarian situation and to IS.
"Behind this question is the serious concern that we do not seem to have a coherent or comprehensive approach to Islamist extremism as it is developing across the globe," he wrote, in a letter published on his website and backed by the Archbishop of Canterbury.
He criticised an "increasing silence" about the plight of tens of thousands of persecuted Christians in Iraq, and questioned whether they would be offered asylum in the UK.
Speaking to Radio 4's Sunday programme, the Bishop of Manchester, the Right Rev David Walker, said the government had a "moral obligation that it is repeatedly failing to rise to".
Shadow foreign secretary Douglas Alexander said the letter from Church leaders had raised "serious questions" about the government's approach to the Middle East and the plight of Christians facing persecution in Iraq and it was "right that [Mr Cameron] now responded".
"The UK government rightly took steps to help avert humanitarian catastrophe in Iraq and Labour has welcomed decisions to now offer support to the Kurdistan regional government and assist Kurdish forces with technical and logistical military equipment.
"But alongside steps to support the Kurdish forces, the UK must now work to engage regional partners to help build a more inclusive and stable government in Iraq.
"That regional approach must focus on supporting and stabilising Jordan, which now shares a border with the Isis-held areas, as well as bringing countries like Turkey into efforts to secure regional stabilisation," he said.
Former Liberal Democrat leader Lord Ashdown told the BBC he believed Mr Cameron's comments were "ill-judged".
"What happens domestically, that's important, but we ought to be creating some kind of strategic policy about curtailing the defining of a widening war, which is much more difficult and important," he said.
He said the PM was also "ill-judged" to talk about defending "our values".
Co-ordinated diplomatic and military action needed to include those who had "universal" values, which "included those in Islam and the East quite as much as those in Christianity and the West", he said.
It is estimated the group has up to 400 recruits from the UK, and some 69 people suspected of Syria-related jihadist activities have now been arrested in the UK.
In late June this year, IS declared that it had created a caliphate, or Islamic state, stretching from Aleppo in Syria to the province of Diyala in Iraq.
IS-led violence has so far driven an estimated 1.2 million Iraqis from their homes.
Whole communities of Yazidis and Christians have been forced to flee in the north, along with Shia Iraqis, whom IS do not regard as true Muslims.