Opioid G protein-coupled receptors (GPCRs) have been implicated in modulating pain, addiction, psychotomimesis, mood and memory, among other functions. We have employed the recently reported crystal structure of the human kappa-opioid receptor (x-OR) and performed molecular dynamics (MD), free energy, and ab initio calculations to elucidate the binding mechanism in complexes with antagonist JDTic and agonist SalA. The two systems were modeled in water and in DPPC lipid bilayers, in order to investigate the effect of the membrane upon conformational dynamics. MD and Atoms in Molecules (AIM) ab initio calculations for the complexes in water showed that each ligand was stabilized inside the binding site of the receptor through hydrogen bond interactions that involved residues Asp138 (with JDTic) and Gln115, His291, Leu212 (with SalA). The static description offered by the crystal structure was overcome to reveal a structural rearrangement of the binding pocket, which facilitated additional interactions between JDTic and Glu209/Tyr139. The role of Glu209 was emphasized, since it belongs to an extracellular loop that covers the binding site of the receptor and is crucial for ligand entrapment. The above interactions were retained in membrane complexes (SalA forms additional hydrogen bonds with Tyr139/312), except the Tyr139 interaction, which is abolished in the JDTic complex. For the first time, we report that JDTic alternates between a "V-shape" (stabilized via a water-mediated intramolecular interaction) and a more extended conformation, a feature that offers enough suppleness for effective binding. Moreover, MM-PBSA calculations showed that the more efficient JDTic binding to kappa-OR compared to SalA (Delta G(JDTic) = -31.6 kcal mol(-1), Delta G(SalA) = -9.8 kcal mol(-1)) is attributed mostly to differences in electrostatic contributions. Importantly, our results are in qualitative agreement with the experiments (Delta G(JDTic,exp) = -14.4 kcal mol(-1), Delta G(SalA,exp) = -10.8 kcal mol(-1)). This study provides previously unattainable information on the dynamics of human kappa-OR and insight on the rational design of drugs with improved pharmacological properties.