Hamas , considered a terrorist organization by the West , wrested control of the legislature from the ruling Fatah party in parliamentary elections last month .