The gut microbiota has an important role in the pathogenesis of hepatic encephalopathy(HE). Rifaximin, an intestinal non-absorbable antibacterial agent, is effective in the treatment of HE. However, whether long-term prophylactic use induces antibacterial resistance and its mechanism for treating HE remains unclear. This prospective study assessed the impact of 12 weeks rifaximin administration on the gut microbiota and resistome in cirrhotic patients. Fecal sampling was conducted 1 day before the first rifaximin administration and at Weeks 1, 2, 4, 6, 8, 10, 12 of the study. Thirty cirrhotic patients who were in remission from recurrent HE was enrolled to receive rifaximin (400mg TID for 12 weeks). Rifaximin improved hyperammonemia and cognitive function in the 21 patients who completed rifaximin treatment. The dynamic observations showed the gut microbiota diversity, composition and the number of resistance genes, plasmids, insertion sequences did not change significantly during the period(P>0.05). Metabolic pathways such as aromatic amino acids, tryptophan synthesis, urea cycle, and LPS synthesis reduced. No new antimicrobial resistance genes was emergenced. However, the number of aminoglycosides, rifamycin and phenolic resistance genes increased, whereas tetracycline, fosfomycin and cephamycin decreased (P<0.05). Changes in the abundance of E. coli, K. pneumoniae, and B. longum strains correlated with changes of resistance genes. Prophylactic use of rifaximin for 12 weeks improved hyperammonemia and neurophysiological function, maintained gut microbiota diversity, composition and did not change the overall resistome. Rifaximin altered expression of HE-related metabolic pathways. All of these effects could play a key role in preventing HE. Clinical Trial Registration: ChiCTR1900022234 (registered at the Chinese Clinical Trial Registry).