Egypt's highest court ruled on Thursday that the last prime minister to serve under Hosni Mubarak can stay in the presidential race and that a third of lawmakers in parliament were illegally elected, forcing a re-vote in a potential blow to Islamists who dominate the legislature.