Justice Secretary Chris Grayling has insisted parliament should have the power to keep prisoners from voting, despite European judges insisting otherwise.

As part of a draft bill, MPs will be given a vote to extend the franchise to convicts serving four years or less. However they could also vote to retain the current blanket ban on prisoner voting - which contravenes rulings by the European Court of Human Rights.

Prime Minister David Cameron previously said the idea of allowing prisoners to vote made him "physically ill", but Mr Grayling said he took his obligation to uphold the rule of law in this case "very seriously".

Grayling told MPs they had the power to "legislate contrary to fundamental principles of human rights".

The defiance from Grayling has greater significance as it arrives just before the ECHR deadline requiring the government to comply with the ruling - a battle which has lasted eight years.

Grayling told Parliament: "The Prime Minister has made clear on the record his personal view on this subject. I have done the same and those views have not changed.

"Equally, it remains the case that parliament is sovereign and the Human Rights Act explicitly recognises that fact. The current law passed by parliament remains in force unless and until parliament decides to change it.

"As Lord Justice Hoffman put it in a case in 1999, parliamentary sovereignty means that parliament can, if it chooses, legislate contrary to fundamental principles of human rights.

"The Human Rights Act 1998 will not detract from this power. The constraints upon its exercise by parliament are ultimately political not legal, but the principle of legality must mean that parliament must squarely confront what it is doing and accept the political cost."

Nils Muižnieks, the new human rights commissioner at the Council of Europe, which oversees the ECHR, disputed the decision from Grayling.

He told the BBC: "The UK decided to delegate some small part of its sovereignty to the Council of Europe when it joined and when it agreed to abide by the rulings of the court.

"There are very few cases when the court rules against the UK. But the court has been very clear on this. It's a breach of the [European convention on human rights] and it should be remedied."

In February, MPs voted by 234 to 22 to keep the blanket ban. Only prisoners on remand are currently allowed to vote.

In 2005, the ECHR said it was up to individual countries to decide which prisoners should be denied the right to vote from jail, but that a total ban was illegal.