India lost their T20 World Cup opener by 10 wickets on Sunday with Shami emerging the most expensive bowler on the night, leaking 43 runs in 3.5 overs.
''Mohammad #Shami we are all with you. These people are filled with hate because nobody gives them any love. Forgive them,'' Gandhi said in a tweet.
Several other politicians also rallied behind the cricketer with former Jammu and Kashmir chief minister Omar Abdullah and Lok Sabha MP Asaduddin Owaisi condemning the targeting of Shami's religious identity by social media trolls.
Former and current India players, including Virender Sehwag and Harbhajan Singh, also extended their support to Shami.
Shami has been one of India's best fast bowlers in recent times and has performed well over the last five years.
The trolls on social media linked his ordinary performance on Sunday night to his religion which did not go down well with fellow netizens with several of them offering support to the 31-year-old.