diff --git a/core/pathresolver.go b/core/pathresolver.go
index 5158999696257065dc38531512fc740187c05780..fce67b11d3d0b1054420b6a5011957371cf8b487 100644
--- a/core/pathresolver.go
+++ b/core/pathresolver.go
@@ -71,16 +71,22 @@ func ResolveToKey(ctx context.Context, n *IpfsNode, p path.Path) (key.Key, error
 		return key.B58KeyDecode(p.Segments()[1]), nil
 	}
 
-	// Fall back onto regular dagnode resolution.
-	dagnode, err := Resolve(ctx, n, p)
+	// Fall back onto regular dagnode resolution. Retrieve the second-to-last
+	// segment of the path and resolve its link to the last segment.
+	head, tail, err := p.PopLastSegment()
+	if err != nil {
+		return key.Key(""), err
+	}
+	dagnode, err := Resolve(ctx, n, head)
 	if err != nil {
 		return key.Key(""), err
 	}
 
-	// Extract and return the node's key.
-	k, err := dagnode.Key()
+	// Extract and return the key of the link to the target dag node.
+	link, err := dagnode.GetNodeLink(tail)
 	if err != nil {
 		return key.Key(""), err
 	}
-	return k, nil
+
+	return key.Key(link.Hash), nil
 }
diff --git a/test/sharness/t0081-repo-pinning.sh b/test/sharness/t0081-repo-pinning.sh
index be0e2e7ea5247479544d2bdb50c4e803a959372b..ca5db950c3b68ad2ce0253fb6f14ba414bfd3d4d 100755
--- a/test/sharness/t0081-repo-pinning.sh
+++ b/test/sharness/t0081-repo-pinning.sh
@@ -283,6 +283,8 @@ FICTIONAL_HASH="QmXV4f9v8a56MxWKBhP3ETsz4EaafudU1cKfPaaJnenc48"
 test_launch_ipfs_daemon
 test_expect_success "test unpinning a hash that's not pinned" "
   test_expect_code 1 ipfs pin rm $FICTIONAL_HASH --timeout=5s
+  test_expect_code 1 ipfs pin rm $FICTIONAL_HASH/a --timeout=5s
+  test_expect_code 1 ipfs pin rm $FICTIONAL_HASH/a/b --timeout=5s
 "
 test_kill_ipfs_daemon