Recently, the Internet of things (IoT) has received a lot of attention from both industry and academia. A reliable and secure IoT connection and communication is essential for the proper working of the IoT network as a whole. One of the ways to achieve robust security in an IoT network is to enable and build trusted communication among the things (nodes). In this area, the existing IoT literature faces many critical issues, such as the lack of intelligent cluster-based trust approaches for IoT networks and the detection of attacks on the IoT trust system from malicious nodes, such as bad service providers. The existing literature either does not address these issues or only addresses them partially. Our proposed solution can firstly detect on-off attacks using the proposed fuzzy-logic based approach, and it can detect contradictory behaviour attacks and other malicious nodes. Secondly, we develop a fuzzy logic-based approach to detect malicious nodes involved in bad service provisioning. Finally, to maintain the security of the IoT network, we develop a secure messaging system that enables secure communication between nodes. This messaging system uses hexadecimal values with a structure similar to serial communication. We carried out extensive experimentation under varying network sizes to validate the working of our proposed solution and also to test the efficiency of the proposed methods in relation to various types of malicious behavior. The experiment results demonstrate the effectiveness of our approach under various conditions.