A man convicted of raping and murdering a three-year-old girl has been executed in public with a machine gun in Yemen.

Muhammad al-Maghrabi was shot to death with a rifle in the capital Sanaa as hundreds of onlookers watched on.

Some of those gathered in the square were pictured photographing and filming the scene on their mobile phones.

Pictures show the 41-year-old lying on the ground on a rug as a police officer holds an AK47-style weapon against his back and opens fire.

Images of the scene also show huge crowds gathered to watch the execution in the city's main square and many people following the police truck carrying al-Maghrabi's dead body after his execution.

Muhammad al-Maghrabi moments before his execution (REUTERS/Khaled Abdullah ) (REUTERS/Khaled Abdullah)

Television cameras reportedly broadcast the sentencing across the country.

In Yemen, Sharia law is the source of all legislation, according to the US State Department.

People gather to watch the execution of Muhammad al-Maghrabi with many taking pictures and filming the scene (REUTERS/Khaled Abdullah ) (REUTERS/Khaled Abdullah)

People gather around a police truck carrying the body of Muhammad al-Maghrabi, 41, after he was executed (REUTERS/Khaled Abdullah ) (REUTERS/Khaled Abdullah)