Simply stated, a mantra is a religious utterance composed in Sanskrit verse and taken from the some part of the Vedas. In other words, a mantra is a piece of Vedic poetry. The verses of the Vedas, including both the Shruti Vedas as well as the Smriti Vedas, are mostly written in verse and therefore are considered mantras. The reason the Vedas are primarily composed in verse as opposed to prose is because they were originally meant to be memorized, not written down, and verse is much easier to memorize than prose.
A mantra is also an utterance composed in a special way to effect a certain result. For example, there can be a specific mantra addressed to a certain Deity, which when chanted properly, is thought to evoke the presence and powers of that Deity. The Gayatri mantra is one such example. The Hare Krishna mantra is another example. In these cases the mantras are often chanted over and over again in a process called japa. The repetition of mantras is called mantra-japa and a devotee many take a vow to repeat a certain mantra many times a day. Often during initiation (diksha) a teacher (guru) will give a special mantra to a disciple and ask him to chant it a certain number of times a day on a set of beads called a japa-mala, similar to a rosary.
A mantra can also be used as part of a spell or charm. There are portions of the Vedas that contain such mantras meant to achieve various purposes. Mantras also have a use in meditation to help achieve a certain state of consciousness. One derivation for the word mantra is man+tra. Man means the mind (from manas) and tra means “to cross,” so a mantra is an utterance that ‘crosses the mind.” In meditation the mind is “crossed over” or silenced. Hence the meaning of the term mantra.