Grinding is a roleplaying game term for playing through repetitive, monotonous battles in order to build experience to make your character more powerful, or collect money in order to buy better equipment (which makes your character more powerful).
One of the most famous early examples of grinding is in the original Final Fantasy. A few hours into the game, the player arrives in the city of Elfland, where powerful but expensive weapons, armor, and magic can be found. The area around Elfland also represents a significant boost in difficulty, suddenly confronting the player with giant ogres, poisonous animals, and the dark elf Astos. Just to the East of Elfland is a marshland where groups of ogres and creeps can be found, and no NES player from the era can forget the hours spent doing battle with them to be able to afford the silver weapons sold there.
Any time a game presents a repetitive task to the player which puts the storyline on hold, it could be called grinding. A well-designed RPG tries to present enough battles to level the characters up naturally over the course of the game (Chrono Trigger for the Super Nintendo being a classic example). A poorly-designed RPG, or one that is trying to pad out the game length, builds in sharp difficulty spikes which require the player to engage in this tedious process before he is powerful enough to continue.
When in-game achievements gained their modern popularity and implementation around 2005, grinding found a new purpose for completing such achievements as "collect one million gold" and "kill one hundred monsters". Whereas grinding used to be largely confined to RPGs, now it can be found in any genre, where unlike their RPG implementation, the process accomplishes nothing but a virtual badge or trophy.
Of course, there will always be that certain breed of player who welcomes the opportunity to grind for levels. Many RPGs have a level cap, that is, a maximum experience level where additional experience doesn't get you anything. Some players just want to see if they can reach that level cap, and others grind in order to make their character as powerful as possible so the next parts of the game become easy. Some games accept this, if you want to spend a few extra hours robbing the game of its challenge, that's your business. Other games implement an anti-grinding mechanic.
Anti-grinding is any of several methods to give players diminishing returns on experience. The most basic example is part of every RPG, where increasing experience levels require exponentially more experience to advance. This means that 10 low-level enemies were enough to get you from level 1 to 2, but it might take 20 or 30 of them to get you from level 2 to 3, unless you progress to the next area, where 10 higher level monsters would give you as much experience as 20 low-level ones.
More advanced games might include reducing the amount of experience low-level enemies give you in addition to requiring more of them to level up, to the point where such fights might start giving you insignificant experience or even no experience at all. Roguelikes such as NetHack have a hunger mechanic, which requires you to keep moving forward or face starvation. Other games simply have a finite number of enemies to kill. One of the best implementations is to include optional side-quests, so that you're still actually playing through story (even if it's a subplot) while gaining levels.
Grinding should not be confused with poopsocking (not leaving your gaming chair for hours on end, pooping in a sock if necessary). While a player who is grinding might very well be poopsocking, a player who is poopsocking is not necessarily grinding.
TVTropes.com has numerous examples of Level Grinding, Forced Level Grinding, and Anti-Grinding.
Leveling treadmill is a related concept.