The present invention relates to a safety device (100) for preventing needlestick injury with a needle (20) comprising : a protective cap (130) and a shield (120) capable of pivoting from a storage position where it is interlocked with the protective cap (130) a retracted position where it gives access to the needle (20) and a safety position where it covers the needle (20) wherein a cam surface (127) of the shield and an engaging peg (137) of the protective cap are arranged so that when the safety device (100) is mounted around the tip (14) of a medical device (10) removing the protective cap (130) from the tip (14) by a distal movement displaces the shield (120) from the storage position to the retracted position. Furthermore the present invention relates to a medical device (10) comprising a tip (14) provided with a needle (20) comprising a needle point (22) wherein the medical device (10) further comprises a safety device (100).