Stalin did not take over the KGB - the KGB was not formed until after his death.
The NKVD, the predecessor of the KGB was formed by Stalin in 1934 - he did not take it over.
Because it was his creation, he appointed its head, and the heads of all its departments, it was totally compliant to his will. However, Stalin was concerned enough to have it's first two heads removed and arrested (Genrikh Yagoda in 1938 and Nikolai Yezhov in 1940).
Stalin removed Trotsky through a mixture of manipulating those around him, and through Trotsky's naivety.
Stalin was able to use his position as General Secretary of the Communist Party to promote his supporters, and to sack his rivals: he slowly removed many Trotsky supporters from the party. Trotsky helped Stalin by forming a faction - The Left Opposition, despite the ban on factions, and then he formed the United Opposition, Stalin used this as his excuse to have him removed from the party and exiled to Soviet Central Asia. Trotsky was arrogant enough to assume that he was too important to the revolution to be removed - he often read books at Politburo meetings - and too naive - assuming that all his rivals were as trustworthy and as humane as he was.