In recent years, Wireless Sensor Networks (WSNs) have become a key technology for monitoring and tracking applications in a wide application range. A wireless sensor network (WSN) senses the environment, collects data, and sends it to a base station (BS) for analysis. A fundamental challenge in designing WSNs is maximizing their lifetimes, especially when energy is limited. Managing trust in the WSN is also a difficult task because trust is used when collaboration is critical to achieving reliable communication. As a result, this paper proposed a secure and energy-aware data aggregation and optimal routing scheme for WSNs based on the Quantum behaviour and Gaussian Mutation based Archimedes Optimization Algorithm (QGAOA). The proposed system comprises three parts: cluster formation, cluster heads (CHs) selection, and optimal routing. Initially, clusters are formed using the Voronoi-included K-means clustering algorithm (VKMCA). Then CHs are selected, and optimal routing is selected using QGAOA. Simulations are carried out to analyze the performance effectiveness of the proposed system with existing related techniques. The results revealed that the proposed system outperformed existing techniques regarding network lifetime (NLT), energy consumption (ECP), throughput, delay, and packet delivery rate (PDR) factors.