The normal expression to use is "by heart". However, both sentences are valid and they mean the same thing. Neither sounds excellent.
To make #1 work better, put the adverbial phrase "from memory" closer to the verb ("knew") that it modifies. The problem with putting it at the end of the sentence is that it appears there to modify "the songs":
"From memory they knew the songs." (best)
"They knew from memory the songs." (acceptable)
Same for #2.
If you use "by heart", you can put it anywhere in the sentence:
"They knew the songs by heart".
The reason "by heart" works even at the end of the sentence is that the expression "by heart" is strongly associated with memorization. Nobody will have any trouble recognizing that it is adverbial and modifies "knew" to express HOW they knew.