Germany reacted with shock and outrage on Tuesday after a 20-year-old petrol station worker was shot dead by a customer angry about being asked to put on a mask while buying beer.

The killing on Saturday evening in the western town of Idar-Oberstein is believed to be the first in Germany linked to the government's coronavirus rules.

The row started when the cashier, a student, told the customer to put on a face mask, as required in all German shops. After a brief argument, the man left.

The suspect then returned about an hour and a half later, this time wearing a mask. But as he brought his six-pack of beer to the till, he took off the mask and another discussion ensued. 

"The perpetrator then pulled out a revolver and shot him straight in the head," prosecutor Kai Fuhrmann told reporters on Monday.

The suspect, a 49-year-old German man, walked to a police station the following day to turn himself in. He was arrested and has confessed to the murder.

He told police he felt "cornered" by the coronavirus measures, which he perceived as an "ever-growing infringement on his rights" and he had seen "no other way out", Fuhrmann said.

Idar-Oberstein mayor Frank Fruehauf called it "an unfathomable, terrible act", and residents have laid flowers and candles outside the petrol station.

The murder comes just days before Germans head to the polls for a general election on September 26 that will see Chancellor Angela Merkel bow out of politics after 16 years.

Katrin Goering-Eckardt, the parliamentary leader of the Green party, tweeted that she was "deeply shaken" by the killing, which she said was "the cruel result of hatred".

Agriculture Minister Julia Kloeckner from Merkel's centre-right CDU party, who hails from the region, said the murder was "shocking".

The Tagesspiegel newspaper said far-right chat groups on Telegram were applauding the murder, with one user writing "Here we go!!!" while others posted thumbs-up emojis.

Germany has seen repeated protests from anti-mask demonstrators throughout the pandemic, some of them attracting tens of thousands of people.

The Querdenker (Lateral Thinkers) movement has emerged as the loudest voice against the government's coronavirus curbs and regulations. Its marches have drawn a wide mix of people, including vaccine sceptics, neo-Nazis and members of Germany's far-right AfD party.

Related Story