your guinea pig needs a visit to the vet. It may have a break or a sprain from a fall or a leg caught in something, and may need some combination of anti-biotics, anti-inflammitories and pain relief, whatever your vet reccommends.
In the mean time, confine your guinea pig to a small area, to restrict movement and lessen the stress on the leg. Keep a good eye on its eating, drinking, pooping and peeing.
best of luck, let us know how the vets visit goes