PIWI-interacting RNAs (piRNAs) provide defence against transposable element (TE) expansion in the germ line of metazoans. piRNAs are processed from the transcripts encoded by specialized heterochromatic clusters enriched in damaged copies of transposons. How these regions are recognized as a source of piRNAs is still elusive. The aim of this study is to determine how transgenes that contain a fragment of the Long Interspersed Nuclear Elements (LINE)-like I transposon lead to an acquired TE resistance in Drosophila. We show that such transgenes, being inserted in unique euchromatic regions that normally do not produce small RNAs, become de novo bidirectional piRNA clusters that silence I-element activity in the germ line. Strikingly, small RNAs of both polarities are generated from the entire transgene and flanking genomic sequences--not only from the transposon fragment. Chromatin immunoprecipitation analysis shows that in ovaries, the trimethylated histone 3 lysine 9 (H3K9me3) mark associates with transgenes producing piRNAs. We show that transgene-derived hsp70 piRNAs stimulate in trans cleavage of cognate endogenous transcripts with subsequent processing of the non-homologous parts of these transcripts into piRNAs.