Variational density-functional theory for degenerate excited states