Shisui gave Itachi his eye.
The eye contains a Genjutsu called KA that can control the victim without them knowing it.
Itachi feared Sasuke might not go back to Konoha on his own, so he programmed Shisui's eye to activate upon seeing Itachi's MS and place the order "Protect Konoha" on Sasuke.
The crow however set it on Itachi.
KA was strong enough to override Edo Tensei's control.
Itachi is a badass and Shisui is even more badass, so Itachi programmed Shisui's genjutsu to order the person having Itachi's eyes (either the eye-thief Sasuke or Itachi himself as a zombie) "protect Konoha". But exactly because Shisui is the real thing, this genjutsu overrided the Edo Tensei control and thus Itachi became a free bird.
Itachi placed the raven with Shishui's eye inside Naruto.He also gave the order protect Konoha.Kotoamatsukami is a very powerful genjutsu that allows the caster to enter the opponents mind and manipulate them by giving them false experiences and making it seem that it was their own.Itachi was manipulated by Kabuto's edo.Shishuis eye activated in Itachi's attempt to kill Naruto and it overcame Kabuto's manipulation.It was a better and more powerfull jutsu than edo so it canceled the effects(the manipulation part) of edo.