By applying Berry-phase theory for the effective half-filled Hubbard model, we derive an analytical expression for the electronic polarization driven by the relativistic spin-orbit (SO) coupling. The model itself is constructed in the Wannier basis, using the input from the first-principles electronic structure calculations in the local-density approximation, and then treated in the spirit of the superexchange theory. The obtained polarization has the following form: ${\bf P}_{ij} = \boldsymbol{\epsilon}_{ji} \boldsymbol{\cal P}_{ij} \cdot [\boldsymbol{e}_i \times \boldsymbol{e}_j]$, where $\boldsymbol{\epsilon}_{ji}$ is the direction of the bond $\langle ij \rangle$, $\boldsymbol{e}_i$ and $\boldsymbol{e}_j$ are the directions of spins in this bond, and $\boldsymbol{\cal P}_{ij}$ is the pseudovector containing all the information about the crystallographic symmetry of the considered system. The expression describes the ferroelectric activity in various magnets with noncollinear but otherwise nonpolar magnetic structures, which would yield no polarization without SO interaction, including the magnetoelectric (ME) effect, caused by the ferromagnetic canting of spins in the external magnetic field, and spin-spiral multiferroics. The abilities of this theory are demonstrated for the the analysis of linear ME effect in Cr$_2$O$_3$ and BiFeO$_3$ and properties multiferroic MnWO$_4$ and $\beta$-MnO$_2$. In all considered examples, the theory perfectly describes the symmetry properties of the induced polarization. However, in some cases, the values of this polarization are underestimated, suggesting that other effects, besides the spin and electronic ones, can also play an important role.