Simple circuit with transistor using Raspberry Pi
This is how you should connect the NPN transistor:



R_GPIO must limit base current to about ten times LED current divided by transistor gain. Assuming a gain of 150 at the specified collector current:

$$R_{GPIO} = {{3.3 V - 0.7 V} \over {10 \cdot {20 mA \over 150}}} \approx 2 k$$