There have been three Hercules rescue flights into Libya. Photograph: Lino Azzopardi/EPA

A pilot of one of the special forces Hercules aircraft that landed in the Libyan desert to evacuate oil workers had a narrow escape when small arms fire entered the cockpit and bounced off his helmet, defence sources have confirmed.

They said a group of rebels fired at the aircraft by mistake, believing that it belonged to forces loyal to Muammar Gaddafi. The rebels later apologised.

The Hercules flew into Libya on Sunday to pick up people stranded in the Sarir oilfield south of Benghazi.

The Ministry of Defence said only that one of its Hercules C130 aircraft appeared to have suffered "minor damage consistent with small arms fire".

It said there were no injuries to passengers or crew and the aircraft returned safely to Malta.

Some of those who were rescued described the moment the Hercules was shot at, forcing it to abandon a landing.

A British oil worker told the BBC: "The aircraft took two hits on the right-hand side of the fuselage, you just heard 'bang bang' as the rounds actually struck."

Another evacuee said that after failing to land at two blocked-off fields, the Hercules was trying again at a third when the firing started. The Hercules rescued 150 people, including 20 Britons.