At the beginning of the Harry Potter series, Neville Longbottom is a character who can't do anything right it seems, who seems somewhat cowardly, etc. But by the time the series is done, he is a very powerful person, who is instrumental in the defeat of Lord Voldemort. What happened that allowed him to make such a powerful change?
As Gilles points out, OotP brings the change in Neville to the forefront. (That's in the books btw, not sure what happens in the movies). The movies, meant for a different kind of audience, generates a new hero in the last part, conveniently labelled Neville. So, if you are referring to the movie version, it's script writers who know what bring in big bucks. If you are referring to the book version, there's a good explanation.
In the books, the main cause of change seems to be
- others expecting more of him
- The news about his parents fate leaking (and their tormentors escaping)
- His being good at Herbology (thanks to Jeff)
I personally believe that Neville was started off simply as a comic relief and as an (sporadic) example of how important will can be and how even the most mediocre and untalented people can do something good. Towards book 4/5, he started gaining importance as an important secondary character. His role still remained the same as the ending of book 1 (when he opposed Harry and friends, is put in a full-body bind and wins Gryffindor the House Cup) - doing the good thing, and doing it very, very mediocrely.
Neville's role towards the end of the franchise is treated somewhat differently in the books and the movies. His dialogues in the movie are quite dramatic, and the bridge scene does not exist in the book. His killing of the snake is also very different in terms of roles. In the book, he is being tortured and he simply draws the sword and kills the snake in an unplanned manner. In the movie, he draws the sword and basically chases the snake and kills it a dramatic moment. So, the Neville of book 7 is closer to that of book 1, who blunders into something with a strong will, while the Neville of movie 7 is actually Rambo in disguise.
EDIT:While answering Chad's comment, I realised that he also became a sort of a hero during the last book. I am talking about his conversation with Harry, and it quite astonished me how Hogwarts and Neville had changed. He stood up to torture, and followed his morals to the utmost. He ran away, but not like the Weasleys or Harry, he tried to make things better. And people actually followed him.
NOTE: I was also very irritated by the romance between Neville and Luna in the movie. The writers seem to be thinking, here's one crazy chick and here's one dumb boy, obviously they hook up because they don't have any other choice.
Neville was never cowardly. He did lack self confidence. But anytime where Neville had to make a choice he made the right choice and stood up for himself and his friends. That was a clear plotline through out the books.
Neville symbolized many people who have greatness with in them but limit themselves through their own self doubt. Neville had many successes but he chose to focus on his failures. This allowed Malfoy and his gang of thugs to pick on Neville which made this effect seem worse. But like all bullies standing up to them when they are picking on you is not where strength comes from. Strength comes from the ability to let the harrassment go and keep trying. Neville never backed down when his friends needed him only when it did not matter.
The books are a journey of self awakening and discovery disguised as magic and action. They are powerful not for the magic and the action but for the inner story that they describe. The heroes are relatable to all of us with their weaknesses and their strengths. They give us hope that put in a position where we had to make difficult choices and take on a threat, that we could overcome and prevail.
The change in Neville is slow, but it starts in Book 1.
Neville's biggest problem has always been that his confidence (or lack thereof) effected his ability to perform. But starting from the very beginning, events have conspired to boost Neville's confidence.
In Book 1, Dumbledore affirms Neville's decision to confront the trio, calls him brave, and makes him the hero of Gryffindor.
In Book 3, Lupin and the boggart help him face and symbolically defeat his fears. He's still afraid of course, but conquering your fears once makes it easier to do it again.
In Book 4, Mad-Eye Moody, possibly the greatest Auror of a generation, singles out Neville and affirms his skills in Herbology. This was part of a plan to help Harry, but there's no evidence that Neville ever learns of that. Even if he does, he doesn't learn until much, much later. Also, he successfully asks a girl out, which is a rather big deal to a 14-year-old.
In Book 5, Neville studies Defense Against the Dark Arts under Harry. As someone whose primary limitation is his confidence, learning under a peer is good for him, and his skills grow rapidly. He then proceeds to accompany Harry in their raid on the Department of Mysteries and faces off with Voldemort's Death Eaters, including Belletrix who tortured his parents, and comes out okay (well, alive and unharmed, at least).
Speaking of his parents, Neville likely regarded his parents' condition with a mixture of pride and shame. Pride because they were injured in the line of duty, and shame because infirmity (particularly mental infirmity) is stigmatized. But in Book 5 Neville's friends learn about his parents, and they proceed to not treat him any differently. It's a small thing, but it likely matters.
Also, Neville's second-hand wand breaks in the Department of Mysteries, and is replaced by a new wand. New wands are generally superior to hand-me-downs.
All of this combined (and more) is what makes Neville the leader of the Hogwarts rebellion, and gives him the confidence to be a true Gryffindor, summon the Sword, and kill Nagini.