The surging global demand for biofuels, precipitated by concerns regarding fossil fuel limitations and their associated environmental consequences has thrust biodiesel into the spotlight as a promising alternative of energy source. In this research endeavor, a novel magnetic catalyst, denoted as K compounds/Fe3O4, was developed by incorporating potassium into the magnetite structure via sol–gel method. This catalyst was applied in the transesterification reaction to convert sunflower and waste cooking oils to biodiesel. It was found that the most effective catalyst for biodiesel produc tion was synthesized by using potassium nitrate at a concentration of 1 M and calcination temperature of 550°C in the catalyst preparation stage. The K compounds/Fe3O4 catalyst was characterized by XRD, XRF, FTIR, SEM, ASAP, and VSM techniques. SEM images demonstrated the porous structure of the catalyst. The GC-mass analysis confirmed the formation of fatty acid methyl esters. The effects of the operating conditions including reactor temperature (55 to 75°C), catalyst dosage (2.5 to 12.5 wt.%), methanol to oil molar ratio (9:1 to 18:1), time (4 to 14 h) were investigated. The best operating conditions were selected inclusive of temperature 65°C, catalyst dosage 5 wt.%, methanol-to-oil ratio 12:1, and time 8 h, and at these operat ing conditions, biodiesel production efficiencies of 96.28% and 84.05% were obtained for sunflower and waste cooking oils, respectively. The reusability and regeneration of the K compounds/Fe3O4 were studied for five cycles.