David Cameron has warned of the threat to the UK if an "extreme Islamist regime" is created in central Iraq.
He said Islamic State of Iraq and the Levant (ISIS) fighters threatening the government in Baghdad were also plotting terror attacks on the UK.
And Britain could not ignore the security threat the UK now faced from jihadists in Iraq and Syria.
Downing Street said 65 people have been arrested in the past 18 months for Syria-related jihadist activities.
A spokesman was unable to say how many of those arrested were supporters or members of ISIS.
The prime minister, who was chairing a meeting of the National Security Council on Wednesday, has ruled out military intervention in support of the government of Iraqi prime minister Nouri al-Maliki.
He said it was up to the Iraqi security forces to "push back" ISIS fighters and also urged the Iraqi government to do more to reconcile Shia, Sunni and Kurdish groups.
But he also stressed that the UK could not ignore the security threat the UK now faced from jihadists in Iraq and Syria, and spoke of the need to help governments "close down ungoverned spaces" to stop the conditions for terrorism flourishing. He also announced extra humanitarian aid for Iraq.
The fighting between ISIS and Iraqi security forces, who are supported by Shia militias, has focused around the city of Baquba, 60km (35 miles) from Baghdad, the Iraqi capital, while Iraq's largest oil refinery is also under attack.
Analysis by BBC Security Correspondent Frank Gardner
At Prime Minister's Questions, David Cameron told MPs: "The people in that regime - as well as trying to take territory - are also planning to attack us here at home in the United Kingdom."
There has been no public threat from ISIS of an attack against the UK and there are no details available of any actual attack planning by it.
However, it is perfectly plausible and there are bound to be things that the intelligence agencies pick up that they share with the National Security Council but not with us, the public.
The worldview of ISIS is vehemently anti-Western. It has an estimated 2,000 recruits from Europe, including 400 to 500 from UK, and it would take just one order from their amir (commander) to send some jihadists back to Britain to carry out an attack.
All the sources I have spoken to say that while "the blowback issue" - the threat of UK jihadists returning to carry out attacks - has not gone away, recent events in Iraq have not so far affected the underlying terror threat to Britain. This remains at 'substantial', the third highest on a scale of five, meaning the threat of a terrorist attack "is a strong possibility".
Speaking at Prime Minister's Questions in the Commons, Mr Cameron said: "I disagree with those people who think this is nothing to do with us and if they want to have some sort of extreme Islamist regime in the middle of Iraq it won't affect us. It will.
"The people in that regime, as well as trying to take territory, are also planning to attack us here at home in the United Kingdom.
"So the right answer is to be long-term, hard-headed, patient and intelligent with the interventions that we make, and the most important intervention of all is to make sure that these governments are fully representative of the people who live in their countries, that they close down the ungoverned space and they remove the support for the extremists."
Mr Cameron also promised to do "absolutely everything we can" to protect Britain from the terrorist threat from fighters returning from Iraq and Syria.
The UK has said up to 400 British nationals are fighting alongside militant groups in Syria.
The prime minister said several people had already been stopped from travelling to conflict zones, and preparing a terrorism offence abroad would become a criminal offence under legislation to be put before Parliament in the next few months.
Downing Street later revealed that the UK security service had arrested 65 people suspected of Syria-related jihadist activities in the past 18 months - including 40 in the first quarter of this year.
The spokesman was unable to say how many of these arrests were linked to people planning to travel to Syria or to offer support to rebels in Syria, and how many related to fighters who had returned from taking part in the civil war.
Up to 14 people have also had their passports seized to stop them going to Syria to fight over the past year.
The total of 14 seizures between April 2013 and March this year related to people suspected of links with terrorism and extremism or serious and organised crime, but the prime minister's official spokesman said "a significant number of them" were Syria-related.
The Downing Street spokesman said the figures underlined the prime minister's warning about the security threat that the UK now faced from jihadists in Iraq and Syria.
"Syria is now the number one source of the jihadist threat," the spokesman added.
'Inform and educate'
Earlier, Baroness Neville-Jones, a former chair of the Joint Intelligence Committee, who was security minister between 2010 and 2011, said the prime minister was right to take the "mounting threat" extremely seriously.
"As a direct threat to us, ISIS has only relatively recently emerged, but it has been operating in Syria for quite some time," she told Radio 4's Today programme.
"Unfortunately the UK exports more young men to become jihadist in Europe than any other. The intelligence picture is clear. The numbers are there."
Older Muslims in communities across the UK, she said, had a responsibility to try to "inform and educate" younger men about the dangers of radicalisation to stop them from travelling to conflict zones.
In the long term, the UK needed to ensure that young Muslim men were fully integrated into their communities and felt that they had a stake in society, she said.