Gunga Din is based on a poem by Rudyard Kipling, the same author who wrote the stories that inspired The Man Who Would Be King and the various adaptations of The Jungle Book. The poem focused on a British soldier recounting an Indian water carrier who died saving his life and realizes how poorly he treated him when he was alive. The 1939 movie added a more detailed plot which the opening credits claim was inspired by "historical fact," but I can't vouch for how accurately this movie depicts anything beyond the fact that the Thuggee were a real secret society in India. The plot is structured as a kind of dark comedy which satirizes the imperfection of the British Empire and draws attention to its mistreatment of the Indian population.
The film opens with a group of British soldiers on a routine patrol, where they encounter a group of men who ask for an escort to the nearest town for "protection." At first, this seems like a fairly straight forward task but to paraphrase one Admiral Ackbar, IT'S A TRAP! Turns out the men are with the Thuggee, and end up ambushing the soldiers in the night. The Thuggee, who serve as the film's main antagonists, are treated as a kind of terrorist group. The film is vague about their exact motivations, goals, or agenda, but they do not appreciate the presence of British soldiers and are willing to die for whatever their cause is.
What becomes a major theme in the case of Gunga Din is the British army's inability to deal with them, and how if anything their presence is often making things worse. We see this when we are introduced to our three heroes, Sergeant Archibald Cutter (Cary Grant, using his real accent for once), Sergeant MacChesney (Victor McLaglan), and Sgt. Thomas Ballantine (Douglas Fairbanks, Jr.). Their introductory scene occurs when they are performing what could easily be seen as a needless act of brutality. More specifically, they appear to have attacked a village and searched a house without warrant, happily throwing people out of a second story window, all because Cutter was apparently swindled by some Scottish infantryman.
Understandably, this one unauthorized action is hardly a competent move, as is much of what the characters do over the course of the story. Two of them are not even motivated by any real sense of patriotism. Cutter displays a largely financial interest, going as far as to disobey orders and break regulations; especially when he learns that there is supposedly a temple of gold nearby which leads him to perform a number of reckless actions. Ballantine is due to be discharged and wants to go into "tea business" and only agrees to take part in the final campaign because of a perceived debt. Meanwhile, Sergeant MacChesney is too wrapped up in military regulations to be able to get anything useful done.
By contrast, Gunga Din himself (Sam Jaffe) is the only one who really has any sense of honor or duty. Early on, it is shown that he is obviously much smarter than anyone is willing to give him credit for. Although he is not a soldier, we see him secretly studying military drills and learning military procedures. even practicing some with Cutter. This knowledge proves especially useful at the film's conclusion, when this experience has allowed Gunga Din to learn how to use a bugle and makes him the only person who is able to alert the army to the Thuggee's trap (this is also after being stabbed, while Cutter is wounded and the other two soldiers have been captured).
In the end, it is Gunga Din who ends up saving the day. Sure, it may have been the British who ultimately defeat the Thuggee, but it was only Gunga Din's efforts that allowed it to happen. The movie ends on this note, with the soldiers deciding to honor Gunga Din's heroics with a posthumous commendation (as well suggesting that the events of the film inspired Kipling's original poem). The film exposes the problems within the British Empire, mocking it and showing it as a flawed system of government.