The American holiday celebrated as Thanksgiving Day has its origins in the Civil War Thanksgiving Proclamations of President Abraham Lincoln. The most famous one was written in October 1863. It proclaims a national day of thanksgiving for the last Thursday in the upcoming month of November. The first national day of thanksgiving was proclaimed by President George Washington on October 3, 1789 and was to be celebrated on Thursday, November 26, 1789. Lincoln followed Washington's example for national days of thanksgiving during the Civil War. One such day was declared in a proclamation dated July 15, 1863, with a national day of thanksgiving set for the upcoming 6th of August. It was "to be observed as a day for National Thanksgiving, praise, and prayer" with "the people of the United States" assembled ...
on that occasion in their customary places of worship ... [to] render the homage due to the Divine Majesty ... and invoke the influence of his Holy Spirit, to subdue the anger ... [of] a needless and cruel rebellion. (245)
On September 28, 1863, Lincoln received a letter from the editor of Godey's Lady's Book, importuning him to establish a permanent annual national day of thanksgiving. The 74-year-old editor Sarah Josepha Hale had been agitating for a national thanksgiving through her editorials for 15 years. Lincoln immediately adopted her idea and on October 3, 1863 set forth his most famous Thanksgiving Proclamation. Lincoln's final October 20, 1864 Proclamation fixed Thanksgiving Day as permanent (267) to remember "Freedom and Humanity" and "Peace, Union and Harmony." Some of the language of the October 1863 Proclamation says:
the country, rejoicing ... is permitted to expect continuance of years with large increase of freedom. ... the gracious gifts of the Most High God, who, while dealing with us in anger for our sins, hath nevertheless remembered mercy. ... I do therefore ... set apart and observe the last Thursday of November next, as a day of Thanksgiving and Praise ... [and] with humble penitence for our national perverseness and disobedience, commend to [Him] ... widows, orphans, mourners or sufferers in the lamentable civil strife ... [that] the Almighty Hand ... heal the wounds ... to the full enjoyment of peace, harmony, tranquility and Union.
How, when, why, and through whom Lincoln's National Day of Thanksgiving became disassociated from Lincoln, freedom, and Union--all central to the Civil War--and re-associated with the October harvest feast of thanksgiving celebrated by the Pilgrims in mid-October of 1621 is unclear--but become disassociated and re-associated it did. Lincoln's thanksgiving for the preservation of the Union and for an increase in freedom and its attendant liberty and equality has been buried under turkeys and Pilgrims. One common thread remains however: Lincoln did eat turkey in the White House on his national days of thanksgiving, praise, and prayer.
The story that we Americans tell is that the holiday of Thanksgiving comes from 1621, when the Pilgrims gave thanks to God because they had survived a particularly difficult winter in Massachusetts. This celebration did happen, but our current Thanksgiving holiday did not come directly from that.
Early in American colonial history, the Puritans had abolished all holidays (like Christmas and saints' days) that had been celebrated in England. To make up for it, they did allow days of Thanksgiving. These days came to be held in Fall to celebrate harvests, just as our current Thanksgiving is held in the Fall.
Thanksgiving became a popular holiday and was celebrated throughout the US. However, it did not become an official holiday, celebrated on the same day throughout the US, until 1941. At that point, Pres. Roosevelt established the holiday on the 4th Thursday of November for economic reasons (to make an "official" start to the Christmas season in hopes of encouraging people to buy more).
That is the history of the holiday. As far as why it is in our history, I would say that it is partly for religious reasons. We are a fairly religious country and believe that it is important to give thanks for our good fortune. Nowadays, the holiday is just as much about family and food as about religion.