The explosion took place at around 5:30 am (0330 GMT) in a site owned by the Bayernoil group near the Bavarian city of Ingolstadt, on the banks of the Danube river.
Public broadcaster Bayerischer Rundfunk said the shockwaves from the blast were felt several kilometers away.
Pictures from the scene showed flames and smoke rising above the refinery as dawn broke.
Three of the victims suffered “medium or serious injuries”, police said in a statement.
Some 1,800 residents of the nearby towns of Vohburg and Irsching were evacuated as a precaution.
“The work to extinguish the flames is continuing,” the police said, adding that there remains “a risk of more explosions”.
Around 200 firefighters were at the scene.
Emergency services appealed to residents within a 20-kilometer (12-mile) radius to “keep their doors and windows closed because of the smoke”.
Bayernoil employs 790 people at two sites in Bavaria and produces petrol, diesel and heating oil, as well as bitumen, with a crude oil processing capacity of 10.3 million tonnes a year, according to its website.
The most recent refinery fire in Germany occurred at a Shell plant in July, and caused no injuries.