A fused heterocyclic compound having an enteropeptidase inhibitory action and use of the compound as a medicament for treatment or prophylaxis of obesity, diabetes mellitus, etc., are provided. Specifically, a compound represented by the following formula (I): wherein each symbol is as defined herein, or a salt thereof and use of the compound as a medicament for treatment or prophylaxis of obesity, diabetes mellitus, etc., are provided.