Cell sorting is a fundamental phenomenon in morphogenesis, which is the process that leads to shape formation in living organisms. The sorting of heterotypic cell populations is produced by a variety of inter-cellular actions, e.g. differential chemotactic response, adhesion and motility. Via a process called chemotaxis, living cells respond to chemicals released by other cells into the environment. Each cell can respond to the stimulus by moving in the direction of the gradient of the cumulative chemical field detected at its surface. Inspired by the biological phenomena of chemotaxis and cell sorting in heterotypic cell aggregates, we propose a chemotaxis-based algorithm for the sorting of self-organizing heterotypic agents. In our algorithm two types of agents are initially randomly placed in a toroidal environment. Agents emit a chemical signal and interact with nearby agents. Given the appropriate parameters, the two kinds of agents self-organize into a complex aggregate consisting of a group of one type of agents surrounded by agents of the second type. This paper describes the chemotaxis-based sorting algorithm, the behaviors of our self-organizing heterotypic agents, evaluation of the final aggregates and parametric studies of the results.