diff --git a/src/plugins/proctrack/cgroup/proctrack_cgroup.c b/src/plugins/proctrack/cgroup/proctrack_cgroup.c
index 847182fc81d33fbe81609fc6140c51914c26e2db..ffd2922b93d5590c81350b29d9f3d937c8979600 100644
--- a/src/plugins/proctrack/cgroup/proctrack_cgroup.c
+++ b/src/plugins/proctrack/cgroup/proctrack_cgroup.c
@@ -270,10 +270,27 @@ bail:
 	return SLURM_ERROR;
 }
 
+static int _move_current_to_root_cgroup(xcgroup_ns_t *ns)
+{
+	xcgroup_t cg;
+
+	if (xcgroup_create(ns, &cg, "", 0, 0) != XCGROUP_SUCCESS)
+		return SLURM_ERROR;
+
+	return xcgroup_move_process(&cg, getpid());
+}
+
 int _slurm_cgroup_destroy(void)
 {
 	xcgroup_lock(&freezer_cg);
 
+	/*
+	 *  First move slurmstepd process to the root cgroup, otherwise
+	 *   the rmdir(2) triggered by the calls below will always fail,
+	 *   because slurmstepd is still in the cgroup!
+	 */
+	_move_current_to_root_cgroup(&freezer_ns);
+
 	if (jobstep_cgroup_path[0] != '\0') {
 		if (xcgroup_delete(&step_freezer_cg) != XCGROUP_SUCCESS) {
 			debug("_slurm_cgroup_destroy: problem deleting step cgroup path %s: %m",