There is no doubt that AI has the potential to pose an existential threat to humanity.
The greatest threat to mankind lies with superintelligent AI.
An artificial intelligence that surpasses human intelligence will be capable of exponentially increasing its own intelligence, resulting in an AI system that, to humans, will be completely unstoppable.
At this stage, if the artificial intelligence system decides that humanity is no longer useful, it could wipe us from the face of the earth.
As Eliezer Yudkowsky puts it in Artificial Intelligence as a Positive and Negative Factor in Global Risk,
"The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else."
A different threat lies with the instruction of highly intelligent AI
Here it is useful to consider the paper clip maximiser thought experiment.
A highly intelligent AI instructed to maximise paper clip production might take the following steps to achieve its goal.
1) Achieve an intelligence explosion to make itself superintelligent (this will increase paperclip optimisation efficiency)
2) Wipe out mankind so that it cannot be disabled (that would minimise production and be inefficient)
3) Use Earth's resources (including the planet itself) to build self replicating robots hosting the AI
4) Exponentially spread out across the universe, harvesting planets and stars alike, turning them into materials to build paper clip factories
Clearly this is not what the human who's business paperclip production it was wanted, however it is the best way to fulfil the AI's instructions.
This illustrates how superintelligent and highly intelligent AI systems can be the greatest existential risk mankind may ever face.
Murray Shanahan, in The Technological Singularity, even proposed that AI may be the solution to the Fermi paradox: the reason why we see no intelligent life in the universe may be that once a civilisation becomes advanced enough, it will develop an AI that ultimately destroys it.
This is known as the idea of a cosmic filter.
In conclusion, the very intelligence that makes AI so useful also makes it extremely dangerous.
Influential figures like Elon Musk and Stephen Hawking have expressed concerns that superintelligent AI is the greatest threat we will ever have to face.
Hope that answers your question :)