LONDON — A man who threw a milkshake at Nigel Farage, the leader of Britain’s Brexit Party, pleaded guilty on Tuesday to the attack and was sentenced to carry out 150 hours of community service and to pay Mr. Farage 350 pounds, about $440, in compensation.

The man, Paul Crowther, 32, hurled the milkshake at Mr. Farage during a campaign event last month in the northeastern city of Newcastle, where the politician was trying to garner support for his newly established Brexit Party before the European Parliament elections.

Mr. Crowther was charged with assault and criminal damage to property for covering Mr. Farage’s suit and face in bright patches of banana and salted caramel milkshake.

As one of the earliest proponents of Brexit, Mr. Farage has been a controversial figure in Britain. During the European Parliament campaign, he spoke in favor of the country’s leaving the European Union without a deal if necessary, a move that analysts warn could lead to shortages of food and medicine, hurt manufacturers, and severely damage Britain’s economy.