Detecting chemical signals is important for identifying food sources and avoiding harmful agents. Like most animals,C. elegansuse olfaction to chemotax towards their main food source, bacteria. However, little is known about the bacterial compounds governingC. elegansattraction to bacteria and the physiological importance of these compounds to bacteria. Here, we address these questions by investigating the function of a small RNA, P11, in the pathogen,Pseudomonas aeruginosa,that was previously shown to mediate learned pathogen avoidance. We discovered that this RNA also affects the attraction of untrainedC. eleganstoP. aeruginosaand does so by controlling production of ammonia, a volatile odorant produced during nitrogen assimilation. We untangle the complex regulation ofP. aeruginosanitrogen assimilation, which is mediated by a partner-switching mechanism involving environmental nitrates, sensor proteins, and P11. In addition to mediatingC. elegansattraction, nitrogen assimilation is important for bacterial fitness and pathogenesis duringC. elegansinfection byP. aeruginosa. These studies define ammonia as a major mediator of trans-kingdom signaling, reveal the physiological importance of nitrogen assimilation for both bacteria and host organisms, and highlight how a bacterial metabolic pathway can either benefit or harm a host in different contexts.