Wireless sensor networks (WSN) encompass numerous sensor nodes deployed in the physical environment to sense parameters and transmit to the base station (BS). Since the nodes in WSN communicate via a wireless channel, security remains a significant issue that needs to be resolved. The choice of cluster heads (CHs) is critical to achieving secure data transmission in WSN. In this aspect, this article presents a novel trust-aware mothflame optimization-based secure clustering (TAMFO-SC) technique for WSN. The goal of the TAMFO-SC technique is to determine the trust level of the nodes and determine the secure CHs. The proposed TAMFO-SC technique initially determines the nodes' trust level, and the node with maximum trust factor can be chosen as CHs. In addition, the TAMFO-SC technique derives a fitness function using two parameters, namely residual energy and trust level. The inclusion of trust level in the CH selection process helps to accomplish security in WSN. A comprehensive experimental analysis exhibits the promising performance of the TAMFO-SC technique over the other compared methods.