Democratic governments must protect the freedom of the internet – even when it provokes crises like the recent anti-Islamic video, the foreign secretary, William Hague, has said.

Addressing an international cyberspace conference in Budapest, he said states should always "err on the side of freedom", even when they found online content offensive or objectionable.

Hague acknowledged the difficulties caused by postings such as the amateur trailer made in the United States which portrayed the prophet Muhammad as a womaniser and a fool.

It was, he said, a "contemptible piece of work" and he deplored the deaths that occurred in the riots it provoked across the Muslim world.

He warned, however, that attempts by governments to block access to such material were counterproductive and doomed to failure.

"We believe that efforts to suppress the internet are wrong and are bound to fail over time," he said.

"Governments who attempt this are erecting barricades against an unstoppable tide, and acting against their own long-term economic interests and their security.

"Democratic governments must resist the calls to censor a wide range of content just because they or others find it offensive or objectionable.

"If we go down that path, we begin to erode the hard-won rights of freedom of expression. We will always argue that it is necessary to err on the side of freedom."

At the same time, Hague announced the UK was establishing a £2m cybersecurity centre offering advice to countries on how to protect their systems against online criminals who threaten the future economic wellbeing of states and major companies.

It will draw on the expertise of a network of eight universities currently conducting cutting-edge research on the issue and act as a forum to draw together initiatives from around the world.

"Cybercriminals and terrorists should have no refuge online, just as they should have no sanctuary offline," Hague said.