BitTorrent is a P2P file-sharing protocol that can be used to efficiently distribute files such as software updates and digital content to very large numbers of users. In a previous paper, we have shown that vulnerabilities can be exploited to launch Denial-of-Service attacks against BitTorrent swarms, which can substantially increase download times and network traffic. In this paper, we review the three most damaging attacks, and propose two algorithms as countermeasures to effectively tackle them. We implemented the attacks and countermeasures in a packet-level BitTorrent simulator. The results indicate that our proposed approach is effective when there is an ongoing attack while at the same time efficient when the countermeasure is active but there is no attack. To the best of our knowledge, this is the first proposal in the literature to make BitTorrent more robust against Denial-of-Service (DoS) attacks. © 2008 IEEE.