Endogenous viral elements (EVEs) are viral sequences integrated in host genomes. A large number of non-retroviral EVEs was recently detected in Aedes mosquito genomes, leading to the hypothesis that mosquito EVEs may control exogenous infections by closely related viruses. Here, we experimentally investigated the role of an EVE naturally found in Aedes aegypti populations and derived from the widespread insect-specific virus, cell-fusing agent virus (CFAV). Using CRISPR-Cas9 genome editing, we created an Ae. aegypti line lacking the CFAV EVE. Absence of the EVE resulted in increased CFAV replication in ovaries, possibly modulating vertical transmission of the virus. Viral replication was controlled by targeting of viral RNA by EVE-derived P-element-induced wimpy testis-interacting RNAs (piRNAs). Our results provide evidence that antiviral piRNAs are produced in the presence of a naturally occurring EVE and its cognate virus, demonstrating a functional link between non-retroviral EVEs and antiviral immunity in a natural insect-virus interaction.