In recent years, the penetration of fuel cells in distribution systems is significantly increased worldwide. The fuel cell is considered an electrochemical energy conversion component. It has the ability to convert chemical to electrical energies as well as heat. The proton exchange membrane (PEM) fuel cell uses hydrogen and oxygen as fuel. It is a low-temperature type that uses a noble metal catalyst, such as platinum, at reaction sites. The optimal modeling of PEM fuel cells improves the cell performance in different applications of the smart microgrid. Extracting the optimal parameters of the model can be achieved using an efficient optimization technique. In this line, this paper proposes a novel swarm-based algorithm called coyote optimization algorithm (COA) for finding the optimal parameter of PEM fuel cell as well as PEM stack. The sum of square deviation between measured voltages and the optimal estimated voltages obtained from the COA algorithm is minimized. Two practical PEM fuel cells including 250 W stack and Ned Stack PS6 are modeled to validate the capability of the proposed algorithm under different operating conditions. The effectiveness of the proposed COA is demonstrated through the comparison with four optimizers considering the same conditions. The final estimated results and statistical analysis show a significant accuracy of the proposed method. These results emphasize the ability of COA to estimate the parameters of the PEM fuel cell model more precisely.