A total of 38 people were killed by a gunman with links to Islamic State extremists on a beach near Sousse.
Writing in the Daily Telegraph, David Cameron urged a fightback, vowing the UK would show "unshakeable resolve" in dealing with extremism.
He stressed the need to reject those who condone the "extremist narrative".
Tributes are continuing to be paid to the British victims, who include three generations of the same family, university graduates and a husband who died trying to shield his wife.
A number of British tourists remain missing, with their relatives continuing to face an agonising wait for news.
None of the dead have been officially identified but the names of some were confirmed by friends and family:
Three Irish people were also killed, along with one Belgian and one German, and Tunisians are also thought to be among the dead. At least 36 people were injured.
The BBC understands the number of British victims - which currently stands at 15 - will rise to at least 30 once the formal identification process is complete.
But it is also understood the process is taking time because of stringent Tunisian regulations, including the local coroner's requirement for medical or dental records.
The UK government also suggested officials were having difficulty identifying British victims as many were not carrying identification and because the injured were being moved between hospitals.
Writing in the Telegraph, Mr Cameron said that as the identities of the dead continued to emerge the full "horror" of events was becoming clear.
"But we will not be cowed," he said. "To our shock and grief we must add another word: resolve. Unshakeable resolve. We will stand up for our way of life.
"So ours must be a full-spectrum response - a response at home and abroad; in the immediate aftermath and far into the future."
He said the Islamic State group used social media as its "primary weapon" and police and security services must have "the tools they need to root out this poison".
Mr Cameron said it was also vital to confront the "poisonous ideology" behind attacks like that carried out in Tunisia.
"We must be stronger at standing up for our values - of peace, democracy, tolerance, freedom," he said.
"We must be more intolerant of intolerance - rejecting anyone whose views condone the Islamist extremist narrative and create the conditions for it to flourish."
BBC political correspondent Robin Brant
He doesn't say it overtly but this is another message to Muslims here and abroad.
With the knowledge that nearly all the victims on that beach in Tunisia were British, David Cameron says: "We must be more intolerant of intolerance" when it comes to extremist views.
The prime minister calls for a rejection of "anyone whose views condone the Islamist extremist narrative".
That is more direct than his words in a speech 10 days ago, when he criticised some British Muslims whom he said "quietly condoned" the actions of groups like Islamic State - but he's not suggesting any new quick fixes or a change to policy.
There is politics though; he says social media online is the primary weapon of Islamic State and he reminds people of the controversial new interception powers the government wants to give the police and security services, saying they must have them to "root out this poison".
Mr Cameron said the UK had a team of more than 50 consular staff, police officers and experts from the Red Cross on the ground in Sousse.
Detectives from the Met Police are among officers there helping with the investigation into the deadliest single terrorist attack on British people since 52 were killed in the London bombings of 2005.
The Tunisian authorities have said they believe the gunman, 23-year-old Seifeddine Rezgui, had help in carrying out the attack.
They believe the suspected accomplices provided the Kalashnikov assault rifle to Rezgui and helped him get to the scene, interior ministry spokesman Mohamed Ali Aroui told AP.
He said the attacker's father and three friends he lived with in Kairouan, where he studied, had been detained for questioning.
We are seeking your stories relating to the Tunisia attacks. If you or anyone you know has been affected please contact us in the following ways.
Please include a contact number if you are willing to speak to a BBC journalist.
Holiday firms put on extra flights over the weekend for people wanting to return home. Flights to the country have also been cancelled.
Meanwhile, the Foreign Office has updated its travel advice to warn that further terrorist attacks in Tunisia are possible, and urged people to be vigilant.
The Tunisian government has brought in increased security measures, with army reservists and extra police to be sent to tourist sites.
Britain is "united in shock and grief", the prime minister has said, as it emerged the British death toll in the Tunisian attack will rise above 30.