In this study, we synthesized molybdenum disulfide/polyaniline (MoS2/PANI) nanocomposite via in situ polymerization of aniline in the presence of thin-layered MoS2. The as-prepared MoS2/PANI nanocomposite obtained an improved electrochemical performance due to the physisorption interaction between aromatic aniline and the basal plane of MoS2. Furthermore, we constructed a new kind of electrochemical sensor based on MoS2/PANI nanocomposite for the detection of chloramphenicol, which showed an excellent performance. The sensor has a high sensitivity and wide detection range from 1 × 10−7 mol/L to 1 × 10−4 mol/L, with a low detection limit of 6.9 × 10−8 mol/L.