tl;dr: it depends.
It's important to distinguish between a debt being "sold" to a debt collector, and when a collector is simply collecting money on the original provider's behalf. In the case of the debt being sold, the original company has already written off the difference and presumably reported it to the credit bureaus. It's likely they won't even accept your payment at this point (rather than accept it and pass on some of it to the collector). In this case it's also likely that even if you pay the debt your credit will not be "un-marked", though it may be updated as paid off, albeit very late.
In the case where the debt collection agency is collecting the money on behalf of the original provider, they keep a percentage of what they collect and pass on the remainder to the provider. In this case the provider (probably) gets more of the money if you pay it directly to the provider, and it's also possible that it hasn't been reported to the credit bureaus yet. In this scenario you are better off paying the provider to prevent them from reporting. Typically utility companies and health providers work this way, so you might have a chance of protecting your credit report by paying directly. (Though I know some utilities won't ding your credit even if you make the payment to the collection agency.) Banks on the other hand typically have already reported it by the time it makes its way to a collection agency.