CARACAS, Venezuela — At least 39 people were killed on Saturday and dozens more were injured in a giant explosion that set off a raging fire at Venezuela’s largest oil refinery, according to officials who rushed to the scene on the Paraguaná Peninsula.

Rafael Ramírez, the energy minister, who is president of Pétroleos de Venezuela, the state-owned oil company that runs the refinery complex, said the blast occurred at 1:15 a.m. and was caused by a gas leak.

Shortly before the explosion, workers at the Amuay refinery detected the buildup of a cloud of gas and began to respond, Mr. Ramírez said, but it was already too late.

“All this happened very fast, and the explosion occurred almost immediately,” Mr. Ramírez said in televised remarks.