Here's why:
* Preposition: The word "in" is a preposition.
* Object of the Preposition: The phrase "the wind" is the object of the preposition "in".
* Function: The entire phrase "in the wind" acts as an adverbial phrase, modifying the verb "swayed" by telling us where the tree swayed.