In this paper, based on the behavior of Caenorhabditis elegans (C. elegans) in response to a toxic substance, we propose a novel biological monitoring method for the detection of water contamination. Both before and after the introduction of formaldehyde into the water at the concentration of 0.1 ppm, the swimming activities of C. elegans are continuously recorded by a charge coupled device camera at the rate of four frames per second. The behavior in each of the image frames is characterized by the branch length similarity (BLS) entropy profile. The shapes quantified by the BLS entropy profiles are classified into seven shape patterns via the self-organizing map combined with the k-means clustering algorithm. Subsequently, a monitoring scheme composed of two hidden Markov models decides the water quality based on the sequence of shape patterns over a certain observation time. The performance of the proposed method is generally affected by the observation interval; yet, experimental results show an accuracy of about 83% for an observation time of five minutes. It is also observed that, by taking the distribution of individual decisions into account, the accuracy of the proposed method can be improved up to 93% and the false negative rate can be reduced to 10%.