Grammatically modifies as a relative clause. It's not that modifies . Japanese is an almost pure head-final language#Head-initial_vs._head-final_languages), which means a modifying part almost always comes before a modified part.
This relative clause is a bit special, and it's a bit hard to give a very literal translation of . This is called a gapless relative clause described here, or type C relative clause described here. Basically explains what kind of we are dealing with. One rather literal translation would be "the sound of water of/from a frog's leaping in." Although this one is grammatically closer to the original haiku, it doesn't look similar to the original in terms of line order. So neither is definitely better than the other.