DORALEH, Djibouti—It was February this year when camel drivers first spotted the Chinese troops staking out a patch of coastal scrubland about 8 miles from the largest U.S. military base in Africa.

Chinese navy ships had visited this tiny East African nation before. They sometimes picked up supplies in the old French port, farther down the arid coast, during antipiracy patrols off Somalia.

This...