Prime Minister Boris Johnson has agreed to resign, his office said Thursday, ending an unprecedented political crisis over his future that has paralyzed Britain's government.