Yes, the meanings of these sentences are different. In the second sentence, "happily" is an adverb of manner which modifies the verb "gave". It means that Peter gave Maria her book in a happy manner, or put another way, Peter was happy when he returned the book.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.