Most states choose Presidential electors based on the candidate who got the most votes in the November election, but not all do. In particular, Nebraska (which has 3 congressional districts and therefore 5 electoral votes) allocates 2 electors to the state-wide winner, and each of the other 3 to the winner in each congressional district. In the 2008 election, Nebraska cast 4 votes for McCain and 1 for Obama, who won a majority of the vote in one district.
Maine has a similar rule, but I don't believe it's split its votes since it established that rule.
But electors are not Constitutionally required to vote as they committed (though there may be penalties under state law). The Constitution leaves it to each state legislature to decide how electors are chosen. All states currently do so by popular vote, but that hasn't always been the case.
There have been a few cases of "faithless electors". Most recently, a 2000 Washington, D.C. elector refused to cast a vote to protest D.C.'s lack of representation in Congress, and a 2004 Minnesota elector wrote the wrong name on the ballot, apparently accidentally.