NiFe2O4 nanoparticles with an average grain size of 31 nm were synthesised by a polyacrylamide gel route. Their bandgap energy obtained by ultraviolet–visible diffuse reflectance spectroscopy is 1·85 eV. NiFe2O4–graphene nanocomposites were fabricated by mixing NiFe2O4 nanoparticles and graphene into absolute ethanol solution followed by thermal drying. Transmission electron microscopy observation shows that NiFe2O4 nanoparticles are well assembled onto graphene sheets. The photocatalytic activity of prepared samples was evaluated by degrading methylene blue under irradiation of simulated sunlight. It is revealed that NiFe2O4–graphene nanocomposites exhibit significantly enhanced photocatalytic activity compared to bare NiFe2O4 nanoparticles. Hydroxyl (•OH) radicals were detected by the photoluminescence technique using terephthalic acid as a probe molecule and are found to be produced on the irradiated NiFe2O4–graphene nanocomposites. Based on the experimental results, •OH radicals are suggested to be the major active species responsible for the degradation reaction.