The vacuum of space isn't a perfect vacuum though so it has a poorly defined temperature - there is always some matter present no matter how tenuous. You can get weird results though when the distribution of particle speeds is nothing like thermal for example in the solar wind.
It is also a property of the now very distant surface of last scattering of the universe in the form of the microwave background from the moment when the previously ionised plasma universe recombined to neutral hydrogen and became transparent to electromagnetic radiation.
Presently after red shifting that looks like about 2.7K from Earth.