Basically it's because of two opposing forces: thermal kinetic expansion and H-bonding. One is the fundamental thermal force, that as things get warmer, the molecules move around more, so they get farther apart and so become less dense. The second force is hydrogen bonding. This occurs in water whereby an O of one molecule will form a weak bond with the H of a neighboring molecule. This causes a kind of hexagonal 3D lattice to form which eventually becomes the 6-sided structure of ice crystals. At 4 degrees C these two forces work out to make water the most dense. That is: the thermal properties are not enough to break all the h-bonds apart, but the h-bonds have not formed enough to widen the distance between water molecules to be as great as in ice (which is why ice is lighter than water).
Here's what everyone said on a particular chemistry email list where your question was posted: "Liquids generally become more dense as the temperature drops because molecular movements are slowing down, allowing the amount of intermolecular interactions to increase. As these intermolecular interactions of water increase, the local arrangements become more like the space-wasting structure of ice, in which each oxygen is surrounded tetrahedrally by four hydrogens." "Water is highly hydrogen-bonded both in the lattice, ice, and in the liquid state. When ice melts, the hydrogen bonds holding the O's in the solid diamond lattice open up and the structure partially collapses, enough to make a fluid, but considerable H-bonding remains and parts of the open, diamond like 3-D lattice remain. R. Gurney called the local structure of liquid water "ice-like." As the temperature rises, more H-bonds are loosened, or broken, allowing further collapse of the open semi-regular ice-like structure, AND more thermal motion ensues tending to open the separation between O's in more random way. Four degrees C happens to be approximately the temperature where these countervailing tendencies cross." [John N. Cooper, Chemistry Bucknell University] "The more vigorous thermal motion of molecules at higher temperatures increases their average distance from each other, promoting a decrease in the density (thermal expansion.) This increased thermal motion also disrupts the hydrogen bonding in water, tending to break up the more open structure associated with efficient hydrogen bonding and thus leading to an increase in its density." [Steve Lower, Simon Fraser University] As water cools toward 4 degrees C, the molecules can still move and vibrate enough to quickly break H bonds and thus can actually bump into each other in non-bonding orientations, that can closely approach and thus overall be more dense. Above 4 degrees C, the motion takes them farther apart and density decreases, as in any material. Below 4 degrees C, the molecules start to form stable H bonds that are actually longer that the van der Waals distances, so the density also decreases and ice expands as more and more H bonds are stabilized into the crystal lattice. The British film, "The Chemistry and Physics of Water" (Lever Brothers) does an excellent job of the graphics showing the H-bonding hexagonal shape which increases water's volume as a function of falling temperature versus the kinetic motion which increases volume as a function of rising temperature. Water is really special stuff, and we need to all be more appreciative of this marvelous environment we evolved in.
Answer: Water above 4C is a liquid which is freely moving around where there are few effects of molecular forces. As the temperature approaches 4C, the liquid molecules come closer together and slow down as their kinetic energy decreases, molecular forces (hydrogen bonding etc) have more of an effect now and bring them closeer together; therefore, the liquid is more dense. As the temperature falls below 4C, the water is starting to order itself to look more like it would as solid ice. That is, it is taking on a form which resembles a number of beachballs stuck together. This is also why ice is less dense than water. Ice has a whole lot of empty space inside these "beachball" structures, whereas liquid water doesn't have this open space.
making a small donation to science.ca.