The present invention relates to a condensed heterocyclic compound that has an enteropeptidase inhibitory effect, and use of the compound as a medicament for the treatment or prevention of obesity, diabetes mellitus, or the like. Specifically, the present invention relates to a compound represented by the formula (I) or a salt thereof, and use of the compound as a medicament for the treatment or prevention of obesity, diabetes mellitus, or the like [in the formula, each symbol is as defined in the specification].