Plants and the insects that feed on them dominate diversity in terrestrial ecosystems: half of all named species are contained within these two groups. Herbivorous insects (herbivores) are abundant and diverse, yet paradoxically, two thirds of insect orders contain no major lineages of herbivores, implying barriers to the evolution of this trophic interaction. How herbivory evolves and why herbivores are so diverse are questions that are key to understanding the processes that have shaped global biodiversity. Yet, most lineages of herbivores are ancient with sister groups either absent or too divergent for a comparative genomic analysis to yield a mechanistic understanding of both their origin and diversification. Many of the exceptions to this pattern are among the Diptera, where lineages such as the leaf-mining drosophilids in the genus Scaptomyza have emerged within the last 10 million years. Scaptomyza is particularly well-suited for identifying the adaptations associated with the evolution of herbivory because it is embedded within the paraphyletic genus Drosophila, which contains species with 25 sequenced genomes, and is closely related to D. melanogaster , the genetic model, and a taxon with one of the most well-studied nervous systems. Behavior is thought to be one of the earliest adaptations during the evolution of herbivory and niche shifts in general. Insects undergoing a niche shift likely lose their preferences for their ancestral diet, and also evolve an attraction to novel cues indicative of their new oviposition substrate. Once females lay eggs in a new environment, herbivores must consume the new diet, despite the fact that it may contain aversive chemicals and a different balance of macronutrients compared to the ancestral diet. Using the herbivorous Scaptomyza flava as a model system, the primary aim of my dissertation was to use methods in comparative genomics, chemical ecology, ethology, and neural imaging to characterize the mechanistic basis of behavioral changes associated with the evolution of herbivory in insects. Using a comparative genomics approach, I found that targeted gain- and loss-of-function mutations were associated with the evolution of herbivory in the genus Scaptomyza. First, four Odorant (Olfactory) Receptor (OR) genes were lost in herbivorous species of Scaptomyza , which are deeply conserved among microbe-feeding drosophilids. The OR genes lost code for receptors that detect yeast-volatiles and are known to stimulate oviposition, feeding and attraction behaviors in Drosophila species. Consistent with these losses was also a loss of detection sensitivity to ligands of these ORs, specifically short-chain aliphatic esters such as ethyl and propyl acetate, major yeast-produced odorants. S. flava female flies were also unresponsive to volatiles produced by active yeast cultures, in contrast to D. melanogaster flies. In contrast to some other specialized lineages of Drosophila , I found no evidence of increased or mass chemosensory gene loss, with one interesting and novel exception. The majority of the genes encoding the Plus-C subfamily of Odorant Binding-like proteins (OBPs) are deleted or pseudogenized in Scaptomyza. Additional conserved cysteine residues that form disulfide bonds that stabilize the tertiary structure characterize this subfamily. Interestingly the extra disulfide bonds in Plus-C OBPs are known to be vulnerable to attack by toxic breakdown products of glucosinolates, isothiocyanates, chemicals that are characteristic of S. flava's host plants in the mustard family. Other than the loss of OBPs, I found S. flava to have multiple duplications of genes encoding ORs, OBPs, gustatory receptors (GRs) and ionotropic receptors (IRs), some of which showed evidence for positive selection (Or67b, Obp49a, Gr33a, Ir67a and Ir76a). Among receptors expressed in the gustatory system, losses, duplications and genes with selection regime changes were more often orthologs of genes expressed in bitter gustatory neurons in D. melanogaster , especially gustatory sensory neurons with a broad expression of gustatory receptor genes. Changes, such as deletions, duplications and increased amino acid substitution rates, were also found among genes encoding receptors implicated in reproductive behavior including the loss of an anti-aphrodisiac receptor, Gr68a, which could be associated with a switch from males chemically guarding mated females with anti-aphrodisiacs to physical guarding behavior where males remain on the backs of females post-mating. (Abstract shortened by ProQuest.