Britain’s top judge has spoken out about media attacks on the judiciary and the failure of politicians to stand up for judges after the Brexit court challenge.

Lord Neuberger, the president of the supreme court, said some of the vitriol directed at the high court judges after they ruled against the government in November was “undermining the rule of law”.

Politicians “could have been quicker and clearer” in their defence of the judiciary, he added in an interview with BBC Radio 4’s Today programme on Thursday.

When three high court judges ruled that parliament should have a say in triggering article 50 to leave the EU, they faced intense criticism from some sections of the media, including a Daily Mail front page describing them as “enemies of the people”.

The justice secretary, Liz Truss, faced fierce criticism for being slow in defending the judges against the media attacks.

Neuberger said: “We [judges] were certainly not well treated. One has to be careful about being critical of the press, particularly as a lawyer or judge, because our view of life is very different from that of the media. I think some of what was said was undermining the rule of law.

“But we all learn by experience, whether politicians or judges. It’s easy to be critical after the event. They were faced with an unexpected situation from which, like all sensible people, they learned.”

After the supreme court hearing, politicians were “certainly vocal quickly enough”, Neuberger added.

“The rule of law together with democracy is one of the two pillars on which our society is based,” Neuberger said, describing judges as “the ultimate guardians” of the rule of law.

Unjustified attacks on the judiciary “risks undermining our society”, he said. “The press and the media generally have a positive duty to keep an eye on things. But I think with that with that power comes the degree of responsibility.”

Neuberger announced last year that he would retire in September.