When the magician Sun En rebelled against Jin rule in 399, Liu Yu joined the army of the general Liu Laozhi (), and he became friends with Liu Laozhi's son Liu Jingxuan (). On one occasion, he led some tens of soldiers on a scouting mission, when they suddenly encountered several thousand of Sun's soldiers. All of Liu Yu's soldiers were killed, and Liu Yu fell onto a riverbank, but he stood his position there and killed all of Sun's soldiers who dared to approach. Liu Jingxuan, meanwhile, realizing that Liu Yu had been away from camp for too long, went to try to find him, and saw him alone chasing and dispersing thousands of Sun's soldiers. He greatly praised Liu Yu.
