The present invention relates to a nitrogen-containing fused ring compound represented by the following formula [I]wherein each symbol is as defined in the specification, or a pharmaceutically acceptable salt thereof, and an anti-HIV agent containing such compound. The compound of the present invention has an HIV integrase inhibitory activity, and is useful as an agent for the prophylaxis or treatment of AIDS, or as an anti-HIV agent. In addition, by the combined use with other anti-HIV agents such as a protease inhibitor, a reverse transcriptase inhibitor and the like, it can be a more effective anti-HIV agent. Because it shows integrase-specific high inhibitory activity, the compound can be a pharmaceutical agent safe on human body, which causes only a fewer side effects.