Can I run a 2.5" tyre on a 40mm rim?
A slightly narrower tire should be fine in terms of fit on the rim. Check the manufacturer's specifications for compatible rim sizes to be sure.

You will lose some volume and impact absorption of course. A narrower tire will have a narrower contact patch so you many find that this decreases grip.