Growing environmental problems along with the galloping rate of population growth have raised an unprecedented challenge to look for an ever-lasting alternative source of energy for fossil fuels. The eternal quest for sustainable energy production strategies has culminated in the electrocatalytic water splitting process integrated with renewable energy resources. The successful accomplishment of this process is thoroughly subject to competent, earth-abundant, and low-cost electrocatalysts to drive the oxygen evolution reaction (OER) and hydrogen evolution reaction (HER), preferably, in the same electrolyte. The present contribution has been dedicated to studying the synthesis, characterization, and electrochemical properties of newfangled electrocatalysts with the formal composition of Mg1−xTMxB2 (x = 0.025, 0.05, and 0.1; TM (transition metal) = Fe and Co) primarily in HER as well as OER under 1 M KOH medium. The electrochemical tests revealed that among all the metal-doped MgB2 catalysts, Mg0.95Co0.05B2 has the best HER performance showing an overpotential of 470 mV at − 10 mA cm−2 and a Tafel slope of 80 mV dec−1 on account of its high purity and fast electron transport. Further investigation shed some light on the fact that Fe concentration and overpotential for HER have adverse relation meaning that the highest amount of Fe doping (x = 0.1) displayed the lowest overpotential. This contribution introduces not only highly competent electrocatalysts composed of low-cost precursors for the water-splitting process but also a facile scalable method for the assembly of highly porous electrodes paving the way for further stunning developments in the field.