Spatial modulation (SM) is affected by the impacts of in-phase and quadrature-phase imbalance (IQI), which cause degradation of system performance in practical terms. To address this concern, an optimal maximum likelihood detector is proposed for SM-based transmission and the system performance is analyzed by computer simulations and analytical derivations. In addition, this optimal receiver is compared with a non-optimal receiver. Specifically, pairwise and average hit error probabilities are derived for the optimal detector. The results prove that IQI is a critical issue for SM-based transmission and the proposed optimal receiver significantly enhances the SM system performance in the presence of IQI.