Background: In wireless sensor network (WSN), one of the best method is data aggregation for energy conservation. In numerous WSN applications, privacy preserving has become a very important issues with the development of WSNs. Purpose: Sensors are vulnerable for security threats due to the open deployment. Moreover, most of the routing algorithms does not consider security. Various methods like trust management, key management, firewalls, and intrusion detection for providing security were considered in the existing work. Between them, enhanced security is given by the trust management. Thus, in this paper, we used the secure trust-based enhanced LEACH routing (STELR) protocol to resolve security concerns. Methods: Here, cluster head is selected by using emperor penguin optimization (EPO) algorithm for data aggregation, and STELR is used to enable the security for routing. We can enable secure communication by checking the trustworthiness of a node. Results: The work is implemented in MATLAB platform, and the results are measured in terms of packet delivery ratio (PDR), throughput, end-to-end (E2E) delay, detection accuracy, energy dissipated, and trust probability (TP). Conclusions: Finally, the security concerns are resolved, which shows proposed approach that gives better performance when compared to existing techniques like LEACH and SDILR protocols.