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 part of Mosul dam from IS fighters in northern Iraq on Sunday. The Pentagon says it destroyed or damaged 19 IS vehicles and a checkpoint near the dam.
|An IS video purports to show Reyaad Khan (c) and Nasser Muthana (r) |
from Cardiff as two of an estimated 400 Britons fighting with the group
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.
|British PM David Cameron|
Mr Cameron said: "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.
"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". He's being diplomatic here in order not to fan an anti-Islam backlash in Britain.
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". Is there a law against recruiting for Jihad?
|A Yazidi refugee girl in Dohuk, northern Iraq|
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.
Breaking media silence on Christian refugees
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.
Earlier this year, Mr Cameron warned that fighters from IS - then named Islamic State of Iraq and the Levant (Isis) - were plotting terror attacks against the UK.
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.
|Christian refugee camp in Dohuk|