The Internet of Things (IoT) has revolutionized the world with its diverse applications and smart connected devices. These IoT devices communicate with each other without human intervention and make life easier in many ways. However, the independence of these devices raises several significant concerns, such as security and privacy preservation due to malicious and compromised nodes within the network. Trust management has been introduced as a less computationally intensive alternative to traditional approaches such as cryptography. The proposed FedTrust approach addresses these challenges by designing a method for identifying malicious and compromised nodes using federated learning. FedTrust trains edge nodes with a provided dataset and forms a global model to predict the abnormal behavior of IoT nodes. The proposed approach utilizes a novel trust dataset consisting of 19 trust parameters from three major components: knowledge, experience, and reputation. To reduce the computational burden, FedTrust employs the concept of communities with dedicated servers to divide the dataset into smaller parts for more efficient training. The proposed approach is extensively evaluated in comparison to existing approaches in terms of accuracy, precision, and other metrics to validate its performance in IoT networks. Simulation results demonstrate the effectiveness of FedTrust by achieving a higher rate of detection and prediction of malicious and compromised nodes.