A safety device for preventing needlestick injury with a needle, including a protective cap and a shield capable of pivoting from a storage position where it is interlocked with the protective cap, a retracted position where it gives access to the needle and a safety position where it covers the needle, wherein a cam surface of the shield and an engaging peg of the protective cap are arranged so that, when the safety device is mounted around the tip of a medical device, removing the protective cap from the tip by a distal movement displaces the shield from the storage position to the retracted position. A medical device including a tip provided with a needle including a needle point, wherein the medical device further includes a safety device.