In seniority, both for demotions and any subsequnet reinstatement.
Which raises an interesting point - my last company downgraded many captains after 9/11. When things picked up again, new captains were being trained before some of the reinstatements. This is because some of the demotees had been originally promoted out of seniority as they had the minimum required hours, wheras many more senior pilots didn't.