Defender is a keyword that has only existed since 2005, but the idea behind defender has existed since the very beginning of Magic. The ability is straightforward, creatures with Defender cannot attack. Prior to the existence of the keyword the concept existed and was represented by creature cards with the creature subtype of walls. It was decided that having specific rules to govern specific subtypes was an added difficulty that was not needed. With the introduction of the keyword ability, the rules for defender coudl actually appear in the rules text of the cards.
As mentioned above, when the game was first introduced the defender existed to some extent as walls. While there are no longer specific rules that apply to walls, all walls do have defender. The official Oracle text of all walls has been changed so walls printed prior to 2005 now have the defender ability.
There are some ways for a creature to lose the defender ability, for example Gargoyle Sentinel has an activated ability that allows the Gargoyle Sentinel to lose defender and gain flying. If a creature loses defender, it is able to attack like a creature without defender would.
As the ability to attack only applies when attacking creatures are declared, giving a creature defender after it has legally attacked will not remove it from combat or somehow retroactively prevent it from attacking.