Barbed wire obviously takes its inspiration from plants that have "barbs" or sharp points that could prevent animals or people from going into or out of places surrounded by such plants. Several persons who developed applications of this idea could be called the inventors of barbed wire, but they didn't patent the idea and therefore have never been fully credited and reimbursed for coming up with the idea.
Leonce Eugene Grassin-Baledans suggested a design for fencing that would be difficult and painful to feel. Louis François Janin was granted a French patent for a design of wire with barbs in 1865. American Michael Kelly had a similar idea, which he suggested would be particularly useful for containing livestock.
In 1867, Lucien B. Smith received a United States patent for a design of barbed wire specifically marketed as a method of corraling and controlling animals. Henry M. Rose's 1873 patent for "The Wooden Strip with Metallic Points" caught the attention of Joseph Glidden, who refined Roses's design and patented the S barb design in his fence, called "The Winner" in 1874.
The exact identity of the inventor of barbed wire depends upon what your criteria are for determining who was first.