There has been horror and hope in the reports from Tunisia over the last few days - horror at the cowardly attack on tourists lying on a beach, but hope too in the fact that, after the attack, hundreds of demonstrators gathered for a rally against terrorism, as they did in the aftermath of the Charlie Hebdo attack in Paris earlier this year.

It demonstrates once again what terrorist attacks always prove: they do not weaken the will to resist and the commitment to democracy, they strengthen it.

However, Tunisia cannot do it alone. As the only democracy in the Arab World, the nation is an important ally in a united, democratic response to the threat of religious terrorism, but the attack in Sousse, in which 38 people died including at least 15 Britons, is a significant challenge to that democracy and part of a rise in Islamic radicalism in the country. One of the international responses to the attacks must be to help the country stay the course.

The UK has its part to play in this. In 2011, the G8 promised Tunisia loans of 25 billion euros which could be used to develop the economy, but four years on, the money has still not materialised. It was offered to Tunisia in the first place because it was recognised that democracy will only flourish there if there is investment and jobs and the same argument holds now. In the words of Tarak Ben Ammar, the prominent Tunisian film producer: "democracy cannot survive on an empty stomach". The G8 should honour its promise and provide Tunisia with the financial support it needs.

As far as the UK is concerned, the more immediate challenge is how to protect its citizens from attack. In the short term, there will be extra security in Tunisian hotels, action will be taken against mosques thought to be radicalising young Muslims, and most British holidaymakers have decided to come home. But in the longer term, British politicians must continue to wrestle with the question at the heart of anti-terrorism: how do you fight and defeat fundamentalism without infringing your citizens' human rights?

The first point to remember, as the First Minister Nicola Sturgeon said as reports emerged that a couple from Cumbernauld were among the victims, is that terrorists such as Seifeddine Rezgui do not speak for Muslims. "Their actions in the name of Islam are a perversion of that faith," she said. It means that the millions of Muslims who live in peace can, and should, be part of the anti-terror strategy.

To be effective and remain true to democratic principles, that strategy should also be based on evidence and intelligence rather than any form of blanket surveillance. In the wake of the Tories' win at the General Election, the Home Secretary Theresa May has revived the Communications Data Bill (or Snoopers' Charter as its enemies prefer to call it) which would require internet service providers to maintain records of every user's activity. But one of the reasons a million people marched through Paris after the Charlie Hebdo attacks was to defend the right to freedom of expression and the UK government needs to consider whether an appropriate response to terrorism is to further restrict individual liberties and the right to privacy. Can blanket surveillance ever be made to work as effectively as targeted, evidence-led intelligence?

As well as intelligence-led efforts to track down British citizens who are planning attacks, the UK must play its part in mobilising international support to bear down on IS. That might mean talking to regimes we would rather avoid, such as Iran and Syria, but it must also mean supporting and encouraging the democratic forces in countries such as Tunisia. Across the Mediterranean Sea, Greece needs all the help it can get to survive a huge financial crisis, but the Tunisian crisis is just as important. Help Tunisia and we will help the democratic world to fight extremism and prevent more attacks such as the one in Sousse.