CAIRO—Egypt's military formalized its ouster of President Mohammed Morsi with the swearing-in of an interim president and the arrests of Mr. Morsi and his Muslim Brotherhood allies.

Adly Mansour, Egypt's new interim president, swore the oath of office in front of Egypt's Supreme Constitutional Court on Thursday morning, after a whirlwind coup, amid massive protests, that overturned an Islamist president who only days ago had seemed immutable.

Mr. Mansour was sworn in hours after Egyptian security forces moved to arrest and detain hundreds of leaders of the Muslim Brotherhood, the powerful Islamist organization that has dominated Egyptian elections over the past two years.

Mr. Morsi was in police custody on Thursday morning after he refused to step down from his post on the orders of Gen. Abdel Fattah al-Sisi on Wednesday night.

Mr. Mansour took two oaths on Thursday morning: The first made him chief justice of the Supreme Constitutional Court and the second elevated him to the presidency.