2N3904 switching application
Consider the 2N3904 driven with 10 mA and controlling a 100 mA load: -



ON-SEMI data sheet was used for the above.

As you can see, the volt drop incurred (collector to emitter) is about 0.35 volts and this is lost across the transistor i.e. the 100 mA load doesn't receive 5 volts; it receives 4.65 volts and this may be enough to cause the problems you are seeing.

With the base connected directly to the IO pin you might be forcing 20 mA+ into the base and the volt drop might only be 0.3 volts across the transistor - this may be "borderline" OK and thus your system appears to work.

I would recommend using an N channel MOSFET having an on-resistance lower than 1 ohm to bottom this problem out - finding a logic level device capable of exhibiting a resistance less than 1 ohm should be fairly straightforward.