With the rapid technological improvements in mobile devices and their inclusion in Internet of Things (IoT), secure key management becomes mandatory to ensure security of information exchange. For instance, IoT applications, such as smart health-care and smart homes, provide automated services to the users with less or no user intervention. As these application use user-sensitive data, ensuring their security and privacy should be paramount, especially during the key management process. However, traditional approaches for key management will not suit well in IoT environment because of the inherent resource constraint property of IoT devices. In this paper, we propose a novel distributed key management scheme for IoT ecosystem. The proposed scheme efficiently provides security to IoT devices by delegating most of the resource consuming cryptographic processing to a local entity. This entity coordinates with other peer entities to provide a distributed key as well as an authentication mechanism to network devices. In particular, the proposed scheme exploits the advantages of mobile agents by deploying them in different subnetworks as and when required: (1) to process the cryptography work for the IoT devices, and (2) to act as an local authenticated entity to perform fast authentication process. To verify the effectiveness and correctness of our proposed scheme, we have simulated it in a large IoT scenario and evaluated against relevant metrics that includes user mobility, certification generation time, and communication overhead.