Let's assume both ships are twelve kilometres long; One equipped with a ten kilometre long spinal railgun,the other with a laser emitter of the same length and configuration. For a laser to function as a weapon,the point of focus (PoF) must be as small as possible. If the beam strikes a target between the emitter an PoF,the weapon loses effectiveness,as the target is not at the focal point. The same is also true if the target is beyond the PoF. Furthermore,lasers diffuse; It's simply the nature of the beast. So,past a certain range,the laser simply can't do any damage at all. As such,lasers have a hard-capped maximum arbitrary range,determined by the emitter in question. Now,while I might not have any numbers,it is safe to assume that a ten kilometre long antishipping laser would require a large amount of power,as the beam would need to be intense enough to cut through dense,multilayered hulls,and potential reflective elements,which would further diminish the effectiveness of the beam. As the beam would need to be needle-thin in order to maintain intensity-on-target,such a weapon,as a pulsed beam,would only be effective at "sniping" critical components; Reactors,ammunition storage,life support,et cetera. As a sustained beam,the weapon becomes a frighteningly effective cutting tool,likely capable of cutting a similar ship in two with three or four kicks at the cat,assuming the target doesn't have an excess of reflective elements in the armour,with pauses between bursts to ensure that the emitter doesn't overheat and fail,or the power drain doesn't cripple other systems,if,for some reason,the ship's designers didn't equip the vessel with a robust enough power supply to feed such a weapon.
The railgun,comparatively,has a literally infinite range at which it can land a kill,no matter how infinitesimally small the odds. At any range beyond the weapon's muzzle,effectiveness isn't lost,while in space. The longer the rails,the higher the weapon's muzzle velocity; If you decide to kick reason to the curb,and go beyond the impossible,you could easily reach a muzzle velocity of 0.9999..C,though a ten kilometre long weapon would likely have a much more "reasonable" muzzle velocity of 0.05C. Now,while the round from a railgun would,by its very nature,lose accuracy at range quite quickly,it would still be able to kill anything the round strikes,be it a hundred kilometres a way,to fifty quintillion kilometres away. As for the victim ship,very little can offer specialised defence against a kinetic assault,so the only way that a similar ship would survive a direct,square hit from the railgun would be with extremely thick sloped and/or curved armour; Any other scenario would result in a gutted shipwreck,from the first shot alone. And,it'd be likely that the round would overpenetrate,and keep going,especially if it struck the side of the target. To power the weapon,you'd likely need far less power than what's needed on the laser dreadnought,thus freeing up resources for other systems,like a laser AMS,potential shielding technology,counterintelligence,and so on. Unless,of course,the shipwrights decided to stick on a tinkertoy generator,for whatever harebrained reason.
All of this said,yes,the laser will be more accurate than the railgun at all ranges. But the railgun would be able to kill at any range. With less power input,from my reckoning,based on what I've observed of real lasers.