We have studied the electronic structure of three-dimensionaltransition-metal–MgB2 alloys, Mg0.97TM0.03B2, (TM = Sc,Ti, V, Cr Mn, Fe, Co, Ni, Cu, Zn) using the Korringa–Kohn–Rostokercoherent-potential approximation method in the atomic-sphere approximation.For unpolarized calculations, our results for Mg0.97TM0.03B2 alloys are similar tothat of 3d impurities in other s and s–p metals. In particular, the local densities ofstates (DOS) associated with the 3d impurities are similar to our earlierwork on 3d impurities in bulk Al (Singh P P 1991 Phys. Rev. B 43 3975;Singh P P 1991 J. Phys.: Condens. Matter 3 3285). For spin-polarizedcalculations, we find only the alloys of V, Cr, Mn, Fe and Co with MgB2to be magnetic of all the 3d elements. We also find that Cr and Mn inMgB2 have a relatively large local magnetic moment of 2.43 and 2.87μB,respectively. We have used the unpolarized, self-consistent potentialsof Mg0.97TM0.03B2 alloys, obtained within the coherent-potentialapproximation, to calculate the electron–phonon coupling constant λ usingthe Gaspari–Gyorffy formalism and the superconducting transition temperatureTcusing the Allen–Dynes equation. We find that the calculatedTcis lowest for Mg0.97Cr0.03B2 and highest for Mg0.97Zn0.03B2, inqualitative agreement with experiment. The calculated trend in variation ofTc fromMn to Zn is also similar to the available experimental data. Our analysis of the variationin Tc,in terms of the DOS and the spectral function along the Γ to Adirection, shows the variation to be an interplay between the total DOS atthe Fermi energy and the creation/removal of states along the Γ to Adirection (Singh P P 2002 Preprint cond-mat/0201093).