The CP violating weak phase phi_s, and the decay width difference Delta Gamma_s between the light and heavy Bs mass eigenstates are measured with the CMS detector at the LHC in a sample of 48 500 reconstructed Bs -> J/psi(mu+mu-)K+K- decays. The measurement is based on a data set corresponding to an integrated luminosity of 96.4/fb, collected in proton-proton collisions at a center-of-mass energy of 13 TeV in 2017--2018. To extract the values of phi_s and Delta Gamma_s, a time-dependent and flavor-tagged angular analysis of the mu+mu-K+K- final state is performed. The analysis employs a novel opposite-side muon flavor tagger based on machine learning techniques, which, in conjunction with a dedicated tagging trigger, allowed to reach an unprecedented tagging power. The measurement yields phi_s = -0.011 +/- 0.050 (stat) +/- 0.010 (syst) rad, and Delta Gamma_s = 0.114 +/- 0.014 (stat) +/- 0.007 (syst) 1/ps, in agreement with the standard model predictions. When combined with our previous measurement at a center-of-mass energy of 8 TeV, the following values are obtained: phi_s = -0.021 +/- 0.045 rad, Delta Gamma_s = 0.1074 +/- 0.0097 1/ps, a significant improvement over the 8 TeV result.