The electronic and magnetic properties of the magnetoelectric solid GaFeO3 are investigated within the generalized gradient approximation including the Hubbard interaction (U) on the localized d orbitals of iron. It was found that using an onsite U=8 eV describes consistently the experimental results. The origin of ferrimagnetism was attributed to the cationic site disorders. The density of states at the iron sites, in a octahedral geometry, show that the occupied eg states are below the t2g states in contradiction with the crystal-field splitting obtained by a point-charge model. However, for the unoccupied states the ab initio data agree qualitatively with the model, showing the complexity of the electron-electron interaction in GaFeO3. The computed electric polarization of the system as a function of the temperature in the linear regime shows a monotonic decreasing trend. To determine the nature of the magnetoelectric coupling, the computed electric polarization as a function of the rotation of the magnetization axis indicates that the magnetoelectric effect observed experimentally could not have been due to a direct coupling between the electric and magnetic order parameters. Finally, the calculated x-ray absorption and x-ray magnetic circular dichroism spectra for the disordered system are shown to be in good agreement with experiment. © 2020 American Physical Society.