Justin Bieber knows when it comes to showbiz, ya gotta know your audience ... which probably explains the song he chose to perform at a prison -- a tune that was sure to connect with inmates.
As we first told you ... JB and his pastor paid a visit to California State Prison in L.A. County to support the prison's faith-based programs -- but until we got this video, we didn't know he'd belted out any hits for them.
Now, we know Justin did a short set during his trip last month, and it included an acoustic rendition of his single, "Lonely."
We're told Bieber sang 3 or 4 of his songs, focusing on slower tracks that translate better with an acoustic guitar accompanying him ... but it's hard to imagine any of his lyrics hitting harder with the inmates than, "I'm so lonely."
We're told by people who were present that Bieber's mini unplugged set was emotional, empathetic and had him on the verge of tears. It was well received by the inmates and followed by a sermon.