How did Peter the Great come into power?

Nominally Peter I and his brother Ivan became co-tsars after death of their eldest brother, tsar Fedor Alexeyevich. In reality, only after he won in struggle with his sister Sophia who proclaimed herself some sort of regent.