The ruling caps months of political turmoil that have overshadowed efforts to deal with the new administration of U.S.