Electromagnetic (EM) methods are widely used for mapping subsurface electrical resistivity structures. Interpreting geophysical EM data often involves solving inversion problems with subjective modeling assumptions, known as hyperparameters. The inherently non-unique nature of EM data inversion, combined with these subjective assumptions, can lead to significantly different solutions among practitioners, complicating the interpretation process. This study introduces a novel modification of the Optimized Particle Swarm Optimization (OPSO) method to simultaneously optimize hyperparameters and physical parameters in 1D EM inversion. A robust objective function based on the L1 norm, designed to prioritize model simplicity, was developed to guide the optimization process. Minimizing this function eliminates the need to manually define the values and dimensions of the model parameters and Lagrange multipliers, enhancing objectivity while evading needlessly complex solutions. Synthetic experiments with transient electromagnetic (TEM) and magnetotelluric (MT) datasets, incorporating 10% and 5% Gaussian noise respectively, achieved best-case weighted mean absolute errors (WMAE) of 0.73 for TEM and 0.84 for MT. The modified OPSO effectively retrieved layer thickness, electrical resistivity, optimal number of layers, and Lagrange multiplier, closely matching the true model for both datasets. The practical applicability of the modified OPSO was validated using real-field data, including the TEM-2-1 dataset acquired from Santolo, Indonesia, and the PCS008 and PC5000 datasets from the COPROD2 MT collection. Best inversion results achieved WMAE values of 0.95 (four-layer model, TEM-2-1), 5.59 (five-layer model, PCS008), and 2.55 (four-layer model, PC5000), demonstrating the method's effectiveness in real-world EM data inversion while avoiding overly complex models.