LONDON - Tech bosses could be jailed if their platforms repeatedly fail to protect children from online harm after Prime Minister Rishi Sunak's government agreed a deal with lawmakers to avoid the prospect of a first parliamentary defeat.

Sunak faced losing a vote in the House of Commons on Tuesday after 50 Conservative lawmakers and the main opposition party said they would support an amendment designed to toughen the Online Safety Bill.

The rebels had tabled an amendment proposing jail sentences of up to two years for tech bosses for failing to protect children from content such as child abuse and self-harm.

The government has agreed to changes to the legislation that will make senior managers at tech firms criminally liable for persistent breaches of the new rules, according to two members of parliament, who asked not to be identified.

This is the third time that Sunak, who has a majority of 67, has backed down in the face of similar revolts in parliament since he took office in October. He previously gave in after rebellions in his party on housing targets and restrictions on onshore wind farms.

Britain, like the European Union and other countries, has been grappling to protect social media users, and in particular children, from harmful content without damaging free speech.

The bill, which is being watched closely by tech executives in the United States, was designed to create one of the toughest online regimes for tech companies in the world, but it was watered down in November, when the government removed the requirement to stop "legal but harmful content".

After days of negotiations between the government and the lawmakers, the two sides reached an agreement with ministers promising to introduce an amendment along similar lines. The rebels will now withdraw their amendment, according to the lawmakers.

Bill Cash, a veteran Conservative lawmaker and one of rebels, told the BBC the agreement with ministers was a "huge step forward" and said that senior managers in the sector "will not want to run the risk of going to jail".

A spokeswoman for the Department for Digital, Culture, Media and Sport did not immediately respond to a request for comment.

(Reporting by Andrew MacAskill Editing by Bernadette Baum)