Electromagnetic field has a great impact on the performance of wireless sensor networks (WSNs). The influence of electromagnetic field generated by power equipment on wireless sensor (WS) nodes is designated as two parameters: environmental electromagnetic interference factor (EEIF) and path loss index (PLI). EEIF is used to describe the probability in the sensor node probability sensing coverage model. PLI is substituted into a node communication path loss model; then, a node packet receiving success rate model can be obtained by above models, which is used to evaluate node communication quality in electromagnetic interference environment. Combined with a service cost model of wireless sensor networks in complex electromagnetic environment, the performance evaluation function of wireless sensor networks is established, and constraints are determined. Solved by the particle swarm optimization (PSO)-gray wolf optimizer (GWO) algorithm, optimal deployment of wireless sensor networks in complex electromagnetic environment is realized. Experimental results show that the proposed method can achieve best performance.