I went out of my way to visit a friend, but he wasn't home.
Literal
Friend [target-に] meet [purpose-に] purposely went-out [but-が], he [topic-は] absent was.
わざわざ ('purposely, going out of one's way') emphasizes the effort spent, making the discovery that the friend was out more frustrating. 留守だった ('was absent/not home') is the standard expression for someone being out.