In the cilia of the nematode Caenorhabditis elegans, anterograde intraflagellar transport (IFT) is mediated by two kinesin-2 complexes, kinesin II and OSM-3 kinesin. These complexes function together in the cilia middle segments, whereas OSM-3 alone mediates transport in the distal segments. Not much is known about the mechanisms that compartmentalize the kinesin-2 complexes or how transport by both kinesins is coordinated. Here, we identify DYF-5, a conserved MAP kinase that plays a role in these processes. Fluorescence microscopy and EM revealed that the cilia of dyf-5 loss-of-function (lf) animals are elongated and are not properly aligned into the amphid channel. Some cilia do enter the amphid channel, but the distal ends of these cilia show accumulation of proteins. Consistent with these observations, we found that six IFT proteins accumulate in the cilia of dyf-5(lf) mutants. In addition, using genetic analyses and live imaging to measure the motility of IFT proteins, we show that dyf-5 is required to restrict kinesin II to the cilia middle segments. Finally, we show that, in dyf-5(lf) mutants, OSM-3 moves at a reduced speed and is not attached to IFT particles. We propose that DYF-5 plays a role in the undocking of kinesin II from IFT particles and in the docking of OSM-3 onto IFT particles.