Turkey’s Justice and Development (AK) party won national elections by a surprisingly large margin, taking 317 of 550 seats in parliament and giving it back the majority it lost in previous elections in June.
This is the first part of one piece from Economist. I can't understand the participle phrase "giving it back the majority". In that phrase, what is "it"? Do "It" happen to indicate "Turkey's Justice and Development (AK) party? Then should "it" be "itself", shouldn't it?