The Swansea student given 56 days in prison for posting racially offensive comments on Twitter should not have been jailed, according to Europe's most senior human rights official.

In an interview the day before he left office, Thomas Hammarberg, the Council of Europe's commissioner for human rights, said the sentence imposed by British courts on 21-year-old Liam Stacey was excessive.

After six years in his post at Strasbourg, the Swedish official used his departing comments to plead for greater freedom of expression and to question blanket imposition of traditional media restraints on the internet.

Stacey, who admitted an offence of racist intent, made repeated, offensive remarks on Twitter after the Bolton Wanderers footballer Fabrice Muamba collapsed during a match. The student's appeal against sentence was dismissed last week.

But Hammarberg told the Guardian: "It was too much. He shouldn't have gone to prison. To put him in prison was wrong.

"Politicians are at a bit of loss to know how to … protect internet freedom while also having regulations against [such problems as] hate speech and child pornography.

"There are limits to freedom of expression but regulators don't know how to handle this. It would be useful to have a more enlightened discussion at a European level, otherwise we are going to have different practices in different countries.

"In traditional media there are editors who are responsible for print content. It's not so easy to have to the same legal procedures when it comes to action [against lone online voices].

"People are at a loss to know how to apply rules for the traditional media to the new media. It's tricky and that's why there needs to be a more thorough discussion about this."

His comments are directly at odds with the enforcement practices of British courts and the views of the attorney general, Dominic Grieve, who has warned that social media and other microblogging sites must not flout the law over such issues as privacy, incitement to hatred or libel.

Dismissing Stacey's appeal against sentence on Friday, the judge, Mr Justice Wyn Williams, sitting with two magistrates, observed: "There are no applicable sentencing guidelines. We have been referred to no previous decided cases either in the court of appeal or at the crown court to assist in determining an appropriate sentence for this type of offence."

The question of how severely online comments should be dealt with echoes the debate over the jailing of several youths who posted remarks encouraging local riots during last summer's disturbances.

Hammarberg also repeated his call for Britain to grant prisoners voting rights and to raise the age of criminal liability – currently one of the lowest in Europe.

He praised the justice secretary, Ken Clarke, for his support for rehabilitation. "My feeling is that he agrees with our assessment … and would like to take another approach to help prisoners rebuild their lives," he said.

"His approach is what we would like the government to take but it is not popular."

The outgoing commissioner reserved his harshest comments for eastern European countries.

He said he had been shocked by what he had seen in countries such as Romania, Ukraine, Russia and Azerbaijan, where there is widespread corruption and "people do not believe that they get justice in courts".

The next human rights commissioner in Strasbourg is a Latvian, Nils Muižnieks, who starts work on Monday.